加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

groovy – 如何在Jenkins工作流中编辑构建参数?

发布时间:2020-12-14 16:28:34 所属栏目:大数据 来源:网络整理
导读:我知道您可以直接在Jenkins工作流中访问构建参数.我有一个名为BRANCH_REVISION的参数,我需要更新,以便调用xml api将显示新值而不是原始值.这是我在使用以下groovy片段的非工作流脚本中所做的事情: def currentParamActions = build.getAction(ParametersAct
我知道您可以直接在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 the build step.

根据org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper这是currentBuild的类型,使用currentBuild.build()代替构建问题中的代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读