Richlewis Richlewis - 1 month ago 16
Groovy Question

Paramertized Build - Jenkins Pipeline

Hoping someone can point me in the right direction.

I have just started to look at the Jenkins pipeline and am trying to work out how to trigger a parameterized build for a job that already exists using the Jenkinsfile

In my Jenkinsfile i have

node {
stage 'Build My Job'
build job: 'my-build'


}

I need to be able to pass a branch name from the Jenkinsfile config to the job that is running? If i am misunderstanding anything then please let me know

Thanks

Answer

Instead of starting with a Jenkinsfile, it's easier to start with a pipeline job in which you can directly edit the pipeline script. By clicking the 'Pipeline Syntax' link you can open the snippet generator, where you can generate the Groovy for a particular step:

This Snippet Generator will help you learn the Groovy code which can be used to define various steps. Pick a step you are interested in from the list, configure it, click Generate Groovy, and you will see a Groovy statement that would call the step with that configuration. You may copy and paste the whole statement into your script, or pick up just the options you care about. (Most parameters are optional and can be omitted in your script, leaving them at default values.)