jenkins - 如何在具有节点,阶段的 Jenkins 文件中使用凭证功能

标签 jenkins google-cloud-platform

当我使用以下代码时,我没有获得谷歌凭据。 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/

相关文章:

bash - 使用 shell/bash 脚本终止谷歌云计算引擎实例

Jenkins Text Finder 中的 Java 正则表达式匹配 2 行

java - Jenkins 中的 PermGen Space 问题

Jenkins 插件构建错误

jenkins - Jenkins 共享库中未调用构造函数

php - Gcloud 错误...gcloud 崩溃 (BadStatusLine) : ''

javascript - Firebase 的云功能是否准时触发?

Jenkins 参数化构建 : build fails due to git parameter includes {^commit}

python - 使用 python 的 GAE 灵活和 Stackriver 日志严重性级别

linux - Google Cloud Ops Agent Mongo 集成错误 - AuthenticationFailed : SCRAM authentication failed, 存储 key 不匹配