小编fs3*_*314的帖子

Jenkins - 将 withCredentials 转换为声明式语法

我有一个 jenkins 管道,它是使用脚本语法编写的,我需要使用声明式样式将其变成一个新管道。

这是我与 jenkins 的第一个项目,我一直在研究如何在声明性 jenkins 中翻译 withCredentials 语法。

原始(脚本化)管道如下所示:

stage('stage1') {
     steps {
        script {
            withCredentials([usernamePassword(credentialsId: CredentialsAWS, passwordVariable: 'AWS_SECRET_ACCESS_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
                parallel (
                    something: {
                         sh 'some commands where there is no reference to the above credentials'
                    }
                )
            }
        }
     }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已将有问题的凭据设置为环境变量,但由于在原始管道中这些未在命令中引用,但它们只是将命令包装为“withCredentials”,我不确定如何实现相同的结果。知道如何做到这一点吗?

jenkins jenkins-pipeline jenkins-declarative-pipeline

2
推荐指数
1
解决办法
1904
查看次数