0

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

4

2 回答 2

1

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.)

于 2016-11-09T09:53:52.270 回答
0

In the configuration page select 'This project is parameterized' and sleect parameter type and enter parameter name

You can access this new parameter value in you jenkinsfile using 'env.parameterName'

于 2016-11-10T07:20:12.677 回答