Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.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声明性管道-与AWS凭证一起使用_Jenkins_Jenkins Pipeline_Jenkins Declarative Pipeline - Fatal编程技术网

Jenkins声明性管道-与AWS凭证一起使用

Jenkins声明性管道-与AWS凭证一起使用,jenkins,jenkins-pipeline,jenkins-declarative-pipeline,Jenkins,Jenkins Pipeline,Jenkins Declarative Pipeline,在我以前的Jenkins文件中,我曾经有这样一个: withCredentials([[ $class: 'AmazonWebServicesCredentialsBinding', credentialsId : 'aws', accessKeyVariable: 'KEY_1', s

在我以前的Jenkins文件中,我曾经有这样一个:

withCredentials([[ $class: 'AmazonWebServicesCredentialsBinding',
                   credentialsId : 'aws',                                                 
                   accessKeyVariable: 'KEY_1',
                   secretKeyVariable: 'KEY_2'
                                     ]]) {
    node(..) { .. } }
e、 g.我需要使用AWS creds的所有阶段都使用withCreds包装,但是使用声明性语法,我必须在每个阶段使用
withCredentials
block,这是不可接受的。我读到在
environments{}
块中有一些
credentials('aws')
选项,尽管我不知道如何在那里指定我的cred类,看起来,这是错误的

pipeline {
   stages {
       stage('A') {
           steps {
              withCredentials([[ $class: 'AmazonWebServicesCredentialsBinding',
                   credentialsId : 'aws',                                                 
                   accessKeyVariable: 'KEY_1',
                   secretKeyVariable: 'KEY_2'
                                     ]]) { .. }
           }
       }
       stage('B') {
           steps {
              withCredentials([[ $class: 'AmazonWebServicesCredentialsBinding',
                   credentialsId : 'aws',                                                 
                   accessKeyVariable: 'KEY_1',
                   secretKeyVariable: 'KEY_2'
                                     ]]) { .. }
           }
       }
   }

}

请让我知道如何用Jenkins声明性语法将我的几个阶段
包装为凭证
。谢谢

您只需使用export命令即可

bindings

    Array/List
    Nested Choice of Objects
    $class: 'AmazonWebServicesCredentialsBinding'
    Sets one variable to the AWS access key and another one to the secret key given in the credentials.
        accessKeyVariable
        Environment variable name for the AWS Access Key Id. If empty, AWS_ACCESS_KEY_ID will be used.
            Type: String
        secretKeyVariable
        Environment variable name for the AWS Secret Access Key. If empty, AWS_SECRET_ACCESS_KEY will be used.
            Type: String
        credentialsId
        Credentials of an appropriate type to be set to the variable.
            Type: String

只需在代码中添加“export accessKeyVariable”和“export secretKeyVariable”,这在其他阶段应该是可用的

我有点搞不懂这是怎么回事。既然“export”是一个shell命令,那么它如何在与withCredentials()上下文相同的执行上下文中运行呢,看起来
withCredentials
只能在
脚本化管道中的
节点
上下文中。我想出了一个解决方案:您可以通过
script
来包装
withCredentials
,例如,
步骤{script withCredentials([[$class:'AmazonWebServicesCredentialsBinding',