承担IAM用户从Jenkins CI上传s3的角色

时间:2019-05-24 15:52:03

标签: amazon-s3 jenkins-pipeline credentials

我正在尝试使用来自Jenkins CI的s3upload,我已经在Jenkins控制台中添加了IAM用户S3_User凭据,并使用了withAWS(区域:s3Region,凭证:s3User)。但是我的IAM用户S3_User没有S3 RW策略,IAM用户必须承担S3_UserRoleWithRWpolicy角色。我该怎么做?

在Jenkins IAM凭据中提供了S3_User访问和密钥,并在IAM Role中添加了S3_UserRoleWithRWpolicy以在IAM角色支持下使用。但是仍然无法从Jenkins上传S3。如何在Jenkins文件中配置使用角色?

1 个答案:

答案 0 :(得分:0)

Finally figured out the solution:

I was using this in Jenkins CI file : 
withAWS(region: 's3Region', credentials: 'iamUser')
{
s3Upload( file:'jar', bucket:s3Bucket, path: s3Path)
}

It worked fine when iamUser has direct access to S3
but failed when iamUser has to assume role to access S3 (after adding IAM Role to Assume in credentials)
But the below worked:

 withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'iamUser']]) {
withAWS(region: 's3Region')
{
s3Upload( file:'jar', bucket:s3Bucket, path: s3Path)
}
}