J'e
J'e

Reputation: 3716

Load Jenkins build parameters from SCM

Is it possible to have Jenkins pull a prameterized build from SCM (Git)?

I'm currently using "Pipeline script from SCM" where Jenkins retrieves the pipeline script but not the build parameters e.g. "String Parameter", "Choice Parameter", etc.

Upvotes: 3

Views: 4778

Answers (2)

pablo.bueti
pablo.bueti

Reputation: 151

Yes, you can retrieve parameters from a Parametrized Build in a Pipeline script from SCM Jenkins job.

To access them in the Jenkins file, use env.[PARAMETER_NAME].

For example:

echo 'Param value: ' + env.SOME_PARAMETER

Upvotes: 0

Sam
Sam

Reputation: 2882

Jenkinsfile (Jenkins pipelines) are capable of this. https://jenkins.io/doc/book/pipeline/syntax/#parameters

Be aware that parameters are post processed. So the 1st build will just be "Build" not "Build with parameters". After the 1st build, it will change.

This can be alleviated by using default values and always referencing the params using the full params.PARAM_NAME syntax. Don't just reference it as PARAM_NAME as this will cause Jenkins to search for env.PARAM_NAME by default.

Upvotes: 4

Related Questions