Jenkins Active Choice反应性参考参数MultiBranch管道作业中格式化的HTML在脚本中获取当前分支名称 [英] Jenkins Active Choice Reactive Reference Parameter Formatted HTML in MultiBranch pipeline job get current branch name in script

查看:222
本文介绍了Jenkins Active Choice反应性参考参数MultiBranch管道作业中格式化的HTML在脚本中获取当前分支名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间试图在MultibranchPipeline作业内部中获得当前分支名称,该参数是Active Choice反应参考参数格式的HTML参数脚本块

I am trying for a lot of time to get the current branch name in MultibranchPipeline Job inside an Active Choice Reactive Reference Parameter Formatted HTML parameter script block

[
    $class: 'DynamicReferenceParameter',
    choiceType: 'ET_FORMATTED_HTML',
    name: 'TestParam',
    omitValueField: true,
    description: 'Test.',
    script: [
        $class: 'GroovyScript',
        fallbackScript: [
            classpath: [],
            sandbox: false,
            script: '''
                return """
                    <p>FallbackScript. Error in main script</p>
                """
            '''
        ], 
        script: [
            classpath: [],
            sandbox: false,
            script: '''
                String branchName = env.BRANCH_NAME
                return """
                    <p>${branchName}</p>
                """
            '''
        ]
    ]
]

问题是,我相信,按下 Build 按钮后,会插入 BRANCH_NAME 参数.

The thing is that, I believe, the BRANCH_NAME param is injected after you press the Build button.

我尝试了很多事情,我的意思是,很多,但我仍然没有设法找到方法. scm 变量也不存在,我尝试使用 jenkins.model.Jenkins.instance 找到东西,但是没有运气.

I've tried a lot of things, and I mean, A LOT, still I didn't manage to find a way. The scm variable doesn't exist as well, I tried to find something with the jenkins.model.Jenkins.instance but no luck.

有可能吗?我很想在他们的Github存储库上问这个问题,但是不允许打开问题.另外,要在Jenkins上开设问题,您还需要一个Jira帐户或其他东西.所以是唯一的地方.

Is it possible? I would love to ask this question on their Github repo, but issues are not allowed to be opened. Also to open an issue on Jenkins you need a Jira account or something. SO is the only place.

推荐答案

看看Groovy的字符串插值.

tl; dr您可以使用",",""和" $ {variable}

tl;dr You can access values by using """ and ${variable}

script: """
    return <p>${env.BRANCH_NAME}</p>
"""

这篇关于Jenkins Active Choice反应性参考参数MultiBranch管道作业中格式化的HTML在脚本中获取当前分支名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆