当我使用以下代码时,我没有获得谷歌凭据。 def GOOGLE_CREDENTIALS = credentials('XYZ Credentials')
最佳答案
[已编辑]
请查看官方guide查看您是否已正确定义它。
同时检查您是否传递了凭据 ID,而不是对 credentials()
方法的描述。
如果您使用的是 Jenkins 管道,您也可以尝试 Credentials Binding Plugin . 来自插件 wiki ,用户名密码类型凭证的典型示例如下所示:
withCredentials([usernamePassword(credentialsId: 'amazon', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
// available as an env variable, but will be masked if you try to print it out any which way
// note: single quotes prevent Groovy interpolation; expansion is by Bourne Shell, which is what you want
sh 'echo $PASSWORD'
// also available as a Groovy variable
echo USERNAME
// or inside double quotes for string interpolation
echo "username is $USERNAME"
}
对于脚本化管道,您也可以使用 withCredentials()
(参见 this):
node {
withCredentials([usernameColonPassword(credentialsId: 'mylogin', variable: 'USERPASS')]) {
sh '''
set +x
curl -u "$USERPASS" https://private.server/ > output
'''
}
}
或者你可以使用 withEnv()
部分:
node {
withEnv(["CREDS=credentials('jenkins-creds')"]) {
stage('Build') {
sh 'printenv'
}
}
}
关于jenkins - 如何在具有节点,阶段的 Jenkins 文件中使用凭证功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53930435/