Jenkins workflow: use parameter as a branch specifier

I want to migrate our old free style collections in which we use the branch name as the build parameter to build the workflow. Until now, it works great, the only thing that we lack is the ability to use a parameter, for example. "branch_name", as the branch qualifier for the Workflow script from the SCM section. In free style, this works great. Any ideas how this can be achieved? We do not want the developer to change the configuration all the time before starting the build.

+5
source share
4 answers

Sounds like JENKINS-28447 :

When you select the "Groovy CPS DSL from SCM" option to specify a stream, SCM plugins do not seem to allow build options or environment variables. I use the git plugin, and when I use it from other tasks I can specify a build parameter, for example, "BuildBranch", and use this when indicating which branch should be built

A workaround would be to use the built-in bootstrap script, which calls load after verification, as described in the tutorial.

+1
source

Try disabling the "Easy check" checkbox.

Lite screen shot

Found in the latest comments JENKINS-28447

+6
source

I have a DSL script workflow described here: https://groups.google.com/forum/#!msg/jenkinsci-users/jSKwSKbaXq8/dG2mn6iyDQAJ

In this script, I have an assembly parameter called FREEBSD_SRC_URL that is passed to the workflow. Based on the different parameters in this URL, you can check another branch.

If you use git, you can still use the same method to pass the build parameter to the script, but you will need to do something a little differently. For example, you can define the BRANCH_NAME parameter in your work and do something like this in a script workflow:

 String checkout_url = "https://github.com/jenkinsci/jenkins" String branch_name = "master" if (getBinding().hasVariable("CHECKOUT_URL")) { // override default URL from build parameter checkout_url = CHECKOUT_URL } if (getBinding().hasVariable("BRANCH_NAME")) { // override default branch from build parameter branch_name = BRANCH_NAME } node { // Do the git checkout git branch: "${branch_name}", url: "${checkout_url}" } 
0
source

Alternatively, go ahead by creating a multi-block workflow project so that each branch is built automatically with its own history.

-1
source

Source: https://habr.com/ru/post/1238956/


All Articles