So, you’ve picked a license, now you need to make sure every source file includes a mention of it. (I don’t know if that’s strictly necessary, but it is highly recommended). You can setup your editor/IDE to include it in a file template, and Jenkins is going to verify every single file has it. Following is my way to set it up (for Objective-C iOS projects, and you can easily tweak it to other languages).
Warnings Plugin
You’ll need to install the Warnings Plug-in: go to Manage Jenkins > Manage Plugins > Available > filter by warning > pick the Warnings Plug-in and hit one of the Install buttons at the bottom.
System setup
Go to Manage Jenkins > Configure System. Find the Compiler Warnings section somewhere towards the bottom, press Add to add a new parser. Here are the parameters:
12345678910
Name: Source Code License Check
Link name: Missing License Warnings
Trend report name: Missing License Trend
Regular Expression: ^(.*)$
Mapping Script:
import hudson.plugins.warnings.parser.Warning
String filename = matcher.group(1)
return new Warning(filename, 1, "License Check", "warning", "Couldn't find the license in the file");
Example Log Message:
./AppDelegate.h
Job setup
In your job, add a new Execute shell build step with the contents:
1
grep -L -r --include '*.h' --include '*.m' --include '*.strings' --include '*.xml' --include '*.json' --exclude 'Contents.json' --exclude-dir '*build' --exclude-dir './ExternalFrameworks''Licensed under the Apache License, Version 2.0 (the "License");' . > license.check || :
Here:
only *.{h,m,strings,xml,json} files are included – I was thinking about an excluding set, but that was bigger than this one. However, I do exclude Contents.json files that are located in .xcassets directories.
*build (various build products) and ./ExternalFrameworks (project’s third-party frameworks) directories are excluded.
'Licensed under the Apache License, Version 2.0 (the "License");' is a standard line from your license of choice, Apache 2.0 in this case.
In the Post-build Actions section, add the Scan for compiler warnings step. Press Add near Scan workspace files. For file pattern enter license.check, and select the Source Code License Check parser. Done. You can build now.