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