KISS

Keep It Simple Stupid

Jenkins: CocoaPods podspec linter

| comments

It’s a quick post on how I set up a build step to lint a podspec file. Quick check: if you’re not using CocoaPods to manage your iOS projects yet, you should try it (read on how to install it with rbenv here! So a podspec is a simple file that describes how your library’s metadata and how to include it in an app.

We’ll need the Warnings Plug-in. Then on the Jenkins config page, Compiler Warnings section, add a new parser with the parameters:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Name: CocoaPods Lint Info Parser
Link name: CocoaPods Lint Info
Trend report name: CocoaPods Lint Info Trend
Regex: ^\s*- (.+)  \| \[(.+?)\](?: \[.+?\])?\s+(.+?):(\d+?):(?:\d*?): (warning|error): (.*)$
Mapping script:
    import hudson.plugins.warnings.parser.Warning
    import hudson.plugins.analysis.util.model.Priority

    String fileName = matcher.group(3)
    int lineNumber = Integer.parseInt(matcher.group(4))
    String type = matcher.group(5)
    String category = matcher.group(1)
    String message = String.format('%s in %s', matcher.group(6), matcher.group(2))
    Priority priority = Priority.NORMAL

    return new Warning(fileName, lineNumber, type, category, message, priority);
Example log message:
    - WARN  | [LibraryName/Core, LibraryName/no-arc, LibraryName/Subspec, and more...]  /Users/Shared/Jenkins/Home/jobs/Library-podspec/workspace/src/File.m:21:10: warning: 'base64Encoding' is deprecated: first deprecated in iOS 7.0 [-Wdeprecated-declarations]

And here is a shell script for a build step in the job:

1
2
3
4
5
6
7
8
# the `pipefail` bash option is required here so the job fails if linting
# fails; by default, bash will only check for the exit code of the latest
# command, and in most cases `tee` will return 0
set -o pipefail

# lint the podspec
pod spec lint --verbose LibraryName.podspec 2>&1 | tee "out/lint.log"
pod lib lint --verbose LibraryName.podspec 2>&1 | tee -a "out/lint.log"

The last step in the necessary Scan for compiler warnings post-build action. File pattern for Scan workspace files is obviously out/lint.log, and pick the CocoaPods Lint Info Parser. Done. Easy.

Comments