我知道您可以直接在Jenkins工作流中访问构建参数.我有一个名为BRANCH_REVISION的参数,我需要更新,以便调用xml api将显示新值而不是原始值.这是我在使用以下groovy片段的非工作流脚本中所做的事情:
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)
但是,似乎这在Workflow中不起作用,因为无法访问构建对象.在此先感谢您的帮助!
解决方法
请参阅<工作流程作业配置> →工作流程→☑片段生成器→全局变量→变量: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.
根据org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper
这是currentBuild的类型,使用currentBuild.build()代替构建问题中的代码.