Triggering pipelines with Jenkins
Prerequisites
- Set up Jenkins as a continuous integration system in your Spinnaker deployment.
- Enable artifact support .
Adding a Jenkins trigger
In the Configuration stage of your new pipeline, add a trigger .
Select Jenkins from the Type menu, which brings up the following screen:
Select a Jenkins master from the Master drop-down menu, then select a job from the Job drop-down.
Add a property file, if desired. See the property files section of the Pipeline Expression Guide for more information about how to specify and use property files.
Build Artifacts
Jenkins has the ability to save files from a build as a build artifacts. These objects could be compiled binaries or kubernetes manifests or any other artifact created as part of the build process.
Best practice dictates that these artifacts should be uploaded to a dedicated artifact repository such as GCR, DockerHub, Artifactory, Maven etc, however sometimes it’s easier to store the artifact as part of the build output.
Here is an example of a Jenkins pipeline that stores artifacts
stages {
stage('Generate Kubernetes Manifests') {
steps {
sh '''
npm install
npm run import
npm run build
echo "BUILD=${BUILD_NUMBER}" > build.properties
'''
}
}
}
post {
always {
archiveArtifacts artifacts: 'dist/*.yaml', fingerprint: true
archiveArtifacts artifacts: 'build.properties', fingerprint: true
}
}
This job will generate the following artifacts
The line echo "BUILD=${BUILD_NUMBER}" > build.properties
adds a build number field to the build.properties which can be used later to generate the URL used to download the artifact using HTTP.
The build.properties artifact should be added to the Jenkins trigger like this
Finally to add the Jenkins build artifact as a Spinnaker artifact, do the following
- Create a HTTP File artifact account for Jenkins using the Jenkins base URL and credentials that has permissions to access the build artifact
- Right click on the build artifact displayed in the Jenkins Build Output above. This will give you the full URL for the build artifact - something like this
https://{jenkins-url}/job/DevToolStack/90/artifact/cdk8s/dist/terraform-operator.k8s.yaml
- Add a new HTTP file artifact to the pipeline replacing the build number with the BUILD field from the properties using the following variable -
${trigger.properties['BUILD']}
like this