git凭证批准不适用于Jenkins管道

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

在我的詹金斯管道中,我有以下代码:

stage('pushing'){
    steps {
        withCredentials([usernamePassword(credentialsId: '91f32d3c-b7ee-49ac-b233-3bd93d2696eb', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
            sh("echo -e 'url=https://domain.tld\nusername=${GIT_USERNAME}\npassword=${GIT_PASSWORD}' | git credential approve")
            sh('git push --tags')
        }
    }
}

输出看起来如下:

[Pipeline] sh
13:28:52 [git-push-tag] Running shell script
13:28:52 + git push --tags
13:28:52 fatal: Authentication failed for 'https://domain.tld/scm/~user/git-push-app.git/'

我已经准备了最小配置的环境:

git config --global user.name jenkins
git config --global user.email [email protected]
git config --global credential.helper cache
git config --global push.default simple
命令行中的

具有以上配置git凭据批准git push --tags对我有用。但这在詹金斯管道中不起作用。

我不知道为什么。

git jenkins jenkins-pipeline credentials
1个回答
0
投票
这只是引号问题,${GIT_USERNAME}之类的env变量不会被内插,因为字符串中包含了单引号。

sh("echo -e 'url=https://domain.tld\nusername=${GIT_USERNAME}\npassword=${GIT_PASSWORD}' | git credential approve") fixed below: sh('echo -e "url=https://domain.tld\nusername=${GIT_USERNAME}\npassword=${GIT_PASSWORD}" | git credential approve')

© www.soinside.com 2019 - 2024. All rights reserved.