转义 @ 字符在 git 的 jenkins 管道中



在我们的 jenkins 构建过程中,我们试图推送到 git。我们的密码最近已更改,现在包含一个@符号,该符号给出以下错误:

建议似乎是对密码进行编码,但我无法弄清楚如何在我们的 jenkins 管道中执行此操作。我该怎么做? (我也尝试使用 replace 方法将 @ 符号换成 %40,但这不起作用。

def GIT_PASSWORD_R = GIT_PASSWORD.replace('@', '%40') 

转义 git 代理密码中的 @ 字符

def GIT_PASSWORD_R = GIT_PASSWORD.toURL()       
git push -f https://${GIT_USERNAME}:${GIT_PASSWORD_R}@github.company.com/Product/subProd.git ${VERSION}-SNAPSHOT

我遇到了同样的问题。另一个对我有用的选项不是编码,而是使用 git 凭据帮助程序。看到这个答案: https://stackoverflow.com/a/40038869/9463800

它设置 git 凭据帮助程序,执行 git 操作,并在 finally 块中取消设置密码。

try {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'MyID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
sh("${git} config credential.username ${env.GIT_USERNAME}")
sh("${git} config credential.helper '!echo password=$GIT_PASSWORD; echo'")
sh("GIT_ASKPASS=true ${git} push origin --tags")
}
} finally {
sh("${git} config --unset credential.username")
sh("${git} config --unset credential.helper")
}

最新更新