Swiftlint: Enabling SwiftLint for Jenkins CI

Created on 27 Jun 2016  路  8Comments  路  Source: realm/SwiftLint

I need an xml file to use it in my Jenkins CI pipeline. I know about checkstyle format, but I always get an error exit code 1. I've been trying with --quiet command but I get the same result. Any suggestion?

question

All 8 comments

I don't understand what problem you're having. Can you elaborate? Keep in mind that SwiftLint will exit 1 if it detects any style violations, so it's normal for it to exit 1 in normal program execution.

I'm just trying to incorporate SwiftLint in my Jenkins Pipeline, so I need to find a way to get an .xml file with the correct format. The second issue is handle exit 1 because Jenkins set the build as failed when run command line. Have you ever merge SwiftLint with Jenkins? Thanks for your help!!!

Yes, we use SwiftLint with Jenkins without issue.

I think you're trying to parameterize SwiftLint with an XML file. That won't work. You can only configure SwiftLint via a YAML configuration file (see docs) or via command line parameters.

SwiftLint _can_ however report its detected violations in a checkstyle XML file:

$ echo "let a = 0" | swiftlint lint --use-stdin --reporter checkstyle > report.xml
Done linting! Found 1 violation, 1 serious in 1 file.
$ cat report.xml
<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="4.3">
  <file name="<nopath>">
    <error line="1" column="1" severity="error" message="Variable name should be between 3 and 40 characters long: 'a'"/>
  </file>
</checkstyle>

I'm just using --use-stdin to demonstrate this example in a short code sample, you'd probably run SwiftLint just directly with swiftlint lint --reporter checkstyle.

I understand your answer and looks good for me, thanks a lot, but I have a second issue because Jenkins set the build as field because of SwiftLint return exit code 1, so I need to tell Jenkins that this is a normal response and not an error. Do you know how? Thanks again!!!

I'm already find a way. I setup the following command inside command shell step:
swiftlint > report.xml || true
Thanks a lot!!!!!!

which jenkins plugin do you use to display a chart with the number of warnings and errors?

@lucatorella how about the Warnings Plugin?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ziryanov picture ziryanov  路  3Comments

BalestraPatrick picture BalestraPatrick  路  3Comments

jcarroll-mediafly picture jcarroll-mediafly  路  3Comments

Tableau-David-Potter picture Tableau-David-Potter  路  3Comments

zntfdr picture zntfdr  路  3Comments