如何动态地将credentialsId传递给Jenkins管道

有没有办法使用环境变量动态传递withCredentials块中Jenkins管道中的credentialsId?

目前这有效:

withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'my-aws-credentials',
                        ACCESS_KEY: 'ACCESS_KEY', SECRET_KEY: 'SECRET_KEY']]) { }

但这不是:

withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: '${AWS_CREDENTIAL_ID}',
                        ACCESS_KEY: 'ACCESS_KEY', SECRET_KEY: 'SECRET_KEY']]) { }

我应该补充说,构建在docker容器中运行,但其他环境变量工作正常,所以我希望这个也可以工作.

最佳答案 实际上,我能够通过这样做来解决它 – >

withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CREDENTIAL_ID,
                        ACCESS_KEY: 'ACCESS_KEY', SECRET_KEY: 'SECRET_KEY']]) { } 
点赞