Automatically archive build artifacts to Amazon's S3 storage

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

要件

  • Your own Amazon S3 bucket(s) and AWS credentials.
  • Amazon's AWS Command Line Interface tools installed on your build agent.

Bamboo's own stock Linux Elastic Bamboo images all come with the AWS CLI pre-installed. If you're using a Windows Elastic Bamboo image or your own custom image, see Amazon's Installing the AWS Command Line Interface page for how to install it manually, and you may need to add the path to the aws binary to your $PATH.

Prepare an S3 bucket

You can create a new bucket or use an existing one. If you have a lot of build plans it's a good idea to have a scheme for bucket naming and directory structure.

Add AWS credentials to Bamboo

You can add them as either global or plan variables so they will be less exposed in the task configuration. Use the word "password" somewhere in the name of the secret key variable in order to hide it in the logs.



Note down artifact locations and copy patterns

For each artifact you want to archive, note down what the location directory and copy patterns are from the artifact definition (from the Artifacts tab of a job).


Add a Script task to the last step of your plan

In these examples, the location of the artifact matches the artifact definition in the screenshot above (inside the "target" directory and the artifact itself is a .war file).

On a Linux agent
#!/bin/bash
export AWS_ACCESS_KEY_ID=${bamboo.awsAccessKeyId}
export AWS_SECRET_ACCESS_KEY=${bamboo.awsSecretAccessKeyPassword}
export AWS_DEFAULT_REGION=us-east-1
 
aws s3 cp target/ s3://name-of-s3-bucket/${bamboo.buildResultKey}/ --recursive --exclude "*" --include "*.war"
On a Windows agent
@echo off
SET AWS_ACCESS_KEY_ID=${bamboo.awsAccessKeyId}
SET AWS_SECRET_ACCESS_KEY=${bamboo.awsSecretAccessKeyPassword}
SET AWS_DEFAULT_REGION=us-east-1
 
aws s3 cp target/ s3://name-of-s3-bucket/${bamboo.buildResultKey}/ --recursive --exclude "*" --include "*.war"

AWS_DEFAULT_REGION should be set to the region your S3 bucket is located in.

Change name-of-s3-bucket to a bucket that you want to use. 

You can add other Bamboo variables here. In these examples, the result key is used to separate the artifacts from different build results from each other.

The aws s3 cp command has other parameters that can be used but this is beyond the scope of this article. For more information, see Amazon's documentation.

最終更新日: 2019 年 10 月 16 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.