从GIT触发到Jenkins buildWithParameters忽略管道中的参数值

问题描述 投票:0回答:1

我有一个GIT(工作正常)的后接收挂钩调用

http://ip:port/job/project_name/buildWithParameters?token=abc&ABC=qwe

ABC是我的参数,在Jenkins的项目中定义为String参数,默认值为xyz。 URL的值为qwe。

enter image description here

我的Jenkins管道脚本是

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                print env.ABC
            }
        }
    }
}

当构建从GIT触发时,env.ABC打印xyz而不是qwe。

enter image description here

如何从URL获取值qwe?我的目标是将版本化的标记名称从GIT传递到管道。

谢谢


编辑#1(来自Matt Schuchard的建议)

不行。

来自收件后挂钩的URL

http://ip:port/job/project_name/buildWithParameters?token=abc&ABC=works&DEF=works

Jenkins UI中为项目定义的参数

enter image description here

管道脚本

pipeline {
    agent any
    parameters {
        string(name: 'DEF', defaultValue: 'failed', description: '')
    }
    stages {
        stage('Checkout') {
            steps {
                print 'by params.ABC -> ' + params.ABC
                print 'by params.DEF -> ' + params.DEF
            }
        }
    }
}

产量

enter image description here


解决方案(由Virginie提供)

有必要引用URL和URL。

http://ip:port/job/project_name/buildWithParameters?token=abc\&ABC=works\&DEF=works

产量

enter image description here

git jenkins jenkins-pipeline githooks
1个回答
0
投票

请注意,如果使用Unix shell脚本,则需要对&进行转义,或者引用整个URL。你能试试这个:

http://ip:port/job/project_name/buildWithParameters?token=abc\&ABC=works\&DEF=works
© www.soinside.com 2019 - 2024. All rights reserved.