How-to guide
Jenkins
Scan each build of a Jenkins pipeline, and fail a pull request build only on the findings that it adds.
Before you start #
- A token for the pipeline. In your workspace, + Add › Set up CI mints the token of one repository and shows this job, with buttons that copy them. Or make the token yourself: see Make a token for the pipeline. Does one CI template or one CI server build many repositories of your team? Then ask an admin for a department token (see Pick a token for the pipeline).
- The install step of your project, before the scan. The examples use
npm ci. See what the job needs before the scan. - The job also keeps malicious packages out of the install (CLI 0.1.94 or later):
tuxcarectl guard checkandtuxcarectl guard setup --cibefore the install step. See Malicious packages.
Add the stage #
Add the token under Manage Jenkins › Credentials as Secret text, with the ID tuxcarectl-portal-token. Then add a stage to the Jenkinsfile:
stage('tuxcarectl') {
environment {
TUXCARE_PORTAL_TOKEN = credentials('tuxcarectl-portal-token')
}
steps {
sh '''
set -e
curl -fsSL https://securechain.tuxcare.com/get/tuxcarectl | sh
export PATH="$HOME/.local/bin:$PATH"
tuxcarectl guard check
guard_path="$(tuxcarectl guard setup --ci)"
eval "$guard_path"
npm ci # the install step of your project, through the guard
tuxcarectl sca --fail-on high
'''
}
}
Fail a pull request only on new findings #
compare --fail-on-new fails a pull request build only on the findings that it adds. The base branch needs a scan of its own, so scan it on each build. See Pull and merge requests.
In a multibranch pipeline, CHANGE_TARGET is set for a pull request build.
sh '''
npm ci # the install step of your project
curl -fsSL https://securechain.tuxcare.com/get/tuxcarectl | sh
export PATH="$HOME/.local/bin:$PATH"
if [ -n "$CHANGE_TARGET" ]; then
tuxcarectl compare --base "$CHANGE_TARGET" --fail-on-new
else
tuxcarectl sca --fail-on high
fi
'''
More #
- Record a release from a tag build (with tag discovery on):
tuxcarectl sca --release "$TAG_NAME". - Send the results to other tools, for example the JUnit test report of Jenkins.
Next: Other CI