简体   繁体   English

如何将TeamCity的artifacts文件夹上传到AWS S3存储桶?

[英]How can I upload TeamCity's artifacts folder into an AWS S3 bucket?

我正在使用S3来托管一个静态网站,并希望能够将TeamCity构建的结果上传到S3存储桶中。

There is third party plugin: https://github.com/guardian/teamcity-s3-plugin 有第三方插件: https//github.com/guardian/teamcity-s3-plugin

Also I would recommend watching for this request in TeamCity tracker as at some point there can be official support: https://youtrack.jetbrains.com/issue/TW-21560 此外,我建议在TeamCity跟踪器中查看此请求,因为在某些时候可以提供官方支持: https//youtrack.jetbrains.com/issue/TW-21560

After working on this for a while, found a solution. 经过一段时间的努力,找到了解决方案。

Having TeamCity Agent hosted in an EC2 instance launched using an IAM Role in AWS. 让TeamCity Agent托管在使用AWS中的IAM角色启动的EC2实例中。

Setup a deployer IAM Role with access to the S3 bucket and allowing TeamCity IAM Role to assume it. 设置部署者IAM角色,可以访问S3存储桶并允许TeamCity IAM角色承担它。

Then use AWS CLI commands to upload content to the bucket. 然后使用AWS CLI命令将内容上载到存储桶。

Example (Powershell) 示例(Powershell)

STEP 1. Request temporary credentials for the account 步骤1.请求帐户的临时凭证

#-----------------------------
# Get parameters
#-----------------------------
$RoleArn = "%param_deployer_arn%"
$ExternalId = "%param_assume_role_external_id%"
$Region = "%param_region%"
$SessionName = "%param_session_name%"

#-----------------------------
# AWS Authentication - Assume Role
#-----------------------------
$Response = (Use-STSRole -Region $Region -RoleArn $RoleArn -ExternalId $ExternalId -RoleSessionName $SessionName).Credentials
$SecretAccessKey = $Response.SecretAccessKey
$SessionToken = $Response.SessionToken
$AccessKeyId = $Response.AccessKeyId

#-----------------------------
# Set environment variables
#-----------------------------
"##teamcity[setParameter name='env.AWS_SECRET_ACCESS_KEY' value='$SecretAccessKey']"
"##teamcity[setParameter name='env.AWS_SECURITY_TOKEN' value='$SessionToken']"
"##teamcity[setParameter name='env.AWS_ACCESS_KEY_ID' value='$AccessKeyId']"

STEP 2. (Access AWS using session token and access key stored in environment variables) 步骤2.(使用会话令牌和存储在环境变量中的访问密钥访问AWS)

IMPORTANT: needs to be done in different step in TeamCity) 重要提示:需要在TeamCity的不同步骤中完成)

#-----------------------------
# List S3 bucket content
#-----------------------------
aws s3 ls s3://%S3Bucket%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM