I know that you can access build parameters directly in the Jenkins Workflow. I have a parameter called BRANCH_REVISION which I need to update so that a call to the xml api will show the new value instead of the original value. This is something I was doing in a non-workflow script using the following groovy snippet:
def currentParamActions = build.getAction(ParametersAction.class)
def currentParams = currentParamActions.getParameters()
currentParams.each() {
if ( it.name.equals("BRANCH_REVISION") ) {
newParams.add( new StringParameterValue("BRANCH_REVISION", newRevision ) )
}
else {
newParams.add( it )
}
}
build.actions.remove(currentParamActions)
new_param_actions = currentParamActions.createUpdated(newParams)
build.actions.add(new_param_actions)
However, it appears that this does not work in Workflow since the build object is not accessible. Thanks in advance for any help!
To execute the Jenkins job from Jenkins web interface first go to respective project workspace and then click on “Build with Parameters” option from left panel. After that, you will be asked to choose/set parameter value (In my project I have set BROWSER parameter.)
If you are trying to get all parameters passed to Jenkins job you can use the global variable params in your groovy pipeline to fetch it.
See <Workflow job configuration> → Workflow → ☑ Snippet Generator → Global variables → Variable: currentBuild:
The
currentBuild
variable may be used to refer to the currently running build. It is an object similar to that documented for the return value of thebuild
step.
Use currentBuild.build()
instead of build
in the code in your question according to org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper
which is the type of currentBuild
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With