Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins Credential插件使用groovy脚本正确解析带有@的用户名和密码_Jenkins_Groovy_Jenkins Plugins_Jenkins Pipeline - Fatal编程技术网

Jenkins Credential插件使用groovy脚本正确解析带有@的用户名和密码

Jenkins Credential插件使用groovy脚本正确解析带有@的用户名和密码,jenkins,groovy,jenkins-plugins,jenkins-pipeline,Jenkins,Groovy,Jenkins Plugins,Jenkins Pipeline,我正在尝试使用Jenkins凭证插件连接到github withCredentials([usernamePassword(credentialsId: gitCredential, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { sh("git push https://${GIT_USERNAME}:${GIT_PASSWORD}@stash.abc.com:656/rad/abl

我正在尝试使用Jenkins凭证插件连接到github

withCredentials([usernamePassword(credentialsId: gitCredential, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
        sh("git push https://${GIT_USERNAME}:${GIT_PASSWORD}@stash.abc.com:656/rad/abl/optical.git --tags")
    }
我正在尝试推入Git,但由于以下错误而失败,因为密码包含@。因为我们无法对从Jenkins凭证插件获得的密码进行URL编码。我正在寻找一种正确解析用户名和密码的方法

[Tagging] Running shell script
+ git push 'https://****:****@stash.abc.com:656/rad/abl/optical.git' --tags
fatal: unable to access 'https://****:ZxmP*K@v6iO/?w4ms@stash.abc.com:656/rad/abl/optical.git': Couldn't resolve host 'v6iO'
[Pipeline] }
[Pipeline] // withCredentials
任何意见都会有帮助


谢谢

这个问题在一次会议上得到了回答。描述如何使用URLEncoder命令对密码中的特殊字符进行编码

在您的情况下,可能是这样的:

withCredentials([usernamePassword(credentialsId: gitCredential, passwordVariable: "GIT_PASSWORD", usernameVariable: "GIT_USERNAME")]) {
    script {
        env.URL_ENCODED_GIT_PASSWORD=URLEncoder.encode(GIT_PASSWORD, "UTF-8")
    }
        sh "git push https://${GIT_USERNAME}:${URL_ENCODED_GIT_PASSWORD}@stash.abc.com:656/rad/abl/optical.git --tags"
}

我认为这个解决方案只有一个问题。对密码进行编码后,jenkins将在不带掩码(****)的情况下输出其值。解决这个问题的一个可能办法是。我看到的另一个解决方案是,但我不知道这是否有效,因为我无法测试它。

哦,凭证密码中的特殊字符似乎是一个常见的恼人问题。如果您将源代码设置为推送URL并使用git凭据帮助器,这会给您带来任何好处吗?我没有试过这个,所以我觉得我不能把它作为一个答案。这里有一些细节值得一看:谢谢@macg33zr,这确实有帮助:)