Passing branch parameter from Jenkins to Spinnaker


#1

I have Spinnaker pipeline setup to be triggered from a Jenkins job. Is there a way to pass a parameter from Jenkins to a Spinnaker pipeline with the GitHub branch that we would like to build? If so, how can it be done?


#2

You can pass a property file from Jenkins to Spinnaker. You will need to archive a file with the branch info as a part of your Jenkins job and specify the file in the Property File field on the Jenkins trigger in Spinnaker. From there, you can reference the branch through pipeline expressions.

Check out https://www.spinnaker.io/guides/user/pipeline-expressions/#property-files for more information.


#3

Thanks for the info. I’m having a little trouble trying to figure out how to pass the property file from Jenkins to Spinnaker. On the Jenkins job that is used to trigger the Spinnaker pipeline, I’ve added a “Post-build Actions” > “Archive the artifacts” > “Files to archive” and specified a file name to archive. Is that how to do it? If not, can you provide some more details on it’s done?

Also do you have an example of how the property files is used once it’s passed to Spinnaker? I’m having trouble figuring out the correct syntax from the pipeline expressions guide.


#4

Yes, that is the correct way to archive the artifact properties file. After running a build, you should see that file you specified under Build Artifacts section in the status page of that Jenkins build. From there, you add that file name to the properties field in the Jenkins trigger on Spinnaker, and Spinnaker will pick up that the properties in the next pipeline run. You can check if the Spinnaker picked up the artifect properites by looking at the execution json of a pipeline with the Jenkins trigger. The properties should be populated in the trigger.properties section of the json.

For an example,
Our property file looks like:

GIT_COMMIT=1234567

and in the comments section of our bake stage we add

${ trigger.properties[‘GIT_COMMIT’]}