gpt4 book ai didi

Jenkins 声明式管道 - 使用 AWS 凭证

转载 作者:行者123 更新时间:2023-12-03 21:23:33 33 4
gpt4 key购买 nike

在我之前的 Jenkinsfile 中,我曾经有过这个:

withCredentials([[ $class: 'AmazonWebServicesCredentialsBinding',
credentialsId : 'aws',
accessKeyVariable: 'KEY_1',
secretKeyVariable: 'KEY_2'
]]) {
node(..) { .. } }

例如我需要使用 AWS 凭证的所有阶段都用 withCreds 包装,但是对于声明性语法,我必须使用 withCredentials区块 每阶段这是 Not Acceptable 。我读到有一些 credentials('aws') environments {} 中的选项阻止,虽然我不知道如何在那里指定我的信用等级,而且看起来似乎是错误的。
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'
]]) { .. }
}
}
}

}

请让我知道如何包装我的几个阶段 withCredentials在 Jenkins 声明式语法中。谢谢

最佳答案

您所要做的就是使用导出命令。

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”,这应该在其他阶段可用。

关于Jenkins 声明式管道 - 使用 AWS 凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49963896/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com