Jon Cox
Jon Cox

Reputation: 10922

Fail an Xcode build on Jenkins if there are Xcode warnings

We've got a Swift iOS project building on Jenkins, using the Xcode plugin.

In the project we're using SwiftLint to validate our code syntax, which produces Xcode warnings or errors if code syntax is incorrect (e.g. if you write something like let num :CGFloat =1).

SwiftLint runs a script after the project has built. So note these are NOT compiler warnings, but Xcode warnings that it pops up.

Is there a way to fail the Jenkins build if there are any Xcode warnings?

Upvotes: 2

Views: 1675

Answers (2)

Jon Cox
Jon Cox

Reputation: 10922

Taking the suggestion from OltzU to use the Warnings Plugin, I installed it on Jenkins.

I then added the Post-build action: Scan for compiler warnings...

set the Parser to Clang (LLVM based)...

clicked on the Advanced... button...

scrolled down a little bit to the Status thresholds (Totals) section...

set the number off acceptable warnings and errors to 0 for All priorities: enter image description here

and saved and rebuilt.

Voila! It now fails builds even with just SwiftLint warnings - thanks to SwiftLint spitting out logs of warnings to the console in the same format as xcodebuild. Happy days 😃

Upvotes: 3

OltzU
OltzU

Reputation: 666

You could use Warnings plugin with custom parser to identify these warnings and set it to fail the build if warnings are found.

Custom parsers can be configured in the Jenkins System configuration after installing the plugin. They require writing a regular expression to catch the lines you are interested in, and groovy scripting for returning a new Warning object for each line matched.

Upvotes: 1

Related Questions