无法打印在詹金斯管道中设置的凭据

时间:2019-06-07 15:47:19

标签: jenkins-pipeline

凭据是在Jenkins中配置的,但是存在错误提示它们没有配置。

我一直遵循Jenkins网站提供的文档。

  agent {
    node {
      label 'master'
    }

  }
  environment {
    AWS_ACCESS_KEY_ID     = credentials('jenkins-aws-secret-key-id')
    AWS_SECRET_ACCESS_KEY = credentials('jenkins-aws-secret-access-key')
  }
  stages {
    stage('checkout') {
      steps {
        git(url: 'git@bitbucket.org:user/bitbucketdemo.git', branch: 'master', credentialsId: 'jenkins')
        echo 'hello'
      }
    }
    stage('packer') {
      steps {
        echo $AWS_ACCESS_KEY_ID
      }
    }
  }
}```



It should print out the value of the environment variable

1 个答案:

答案 0 :(得分:0)

我使用了Cloudbees AWS Credentials插件。安装后,我能够添加我的AWS凭证(在“凭证”下拉菜单中的其他选择)

enter image description here

然后在我的Jenkinsfile中使用以下代码段

withCredentials(
                [[
                    $class: 'AmazonWebServicesCredentialsBinding',
                    accessKeyVariable: 'AWS_ACCESS_KEY_ID',
                    credentialsId: 'AWS',
                    secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
                ]]) {
                  sh 'packer build -var aws_access_key=${AWS_ACCESS_KEY_ID} -var aws_secret_key=${AWS_SECRET_ACCESS_KEY} example4.json'
                }
相关问题