LoginSignup
5
5

More than 5 years have passed since last update.

BitbucketのPipelinesで特定ディレクトリをAWS S3へデプロイする

Last updated at Posted at 2016-12-20

やりたいこと

今までBitbucketからAWS S3へのデプロイをwerckerで行っていたが、Bitbucket PipelinesがリリースされたのでBitbucket内で完結させたい。

結論

先にBitbucket PipelinesのEnvironment variablesにAWS_SECRET_ACCESS_KEYAWS_ACCESS_KEY_IDを登録しておく。
その上でbitbucket-pipelines.ymlを作成。

bitbucket-pipelines.yml
image: python:3.5.1

pipelines:
  branches:
    develop:
      - step:
          script:
            - echo "deply to test bucket."
            - pip install awscli
            - aws s3 sync dist/ s3://バケット名 --exact-timestamps --delete
    master:
      - step:
          script:
            - echo "deply to production bucket."
            - pip install awscli
            - aws s3 sync dist/ s3://バケット名 --exact-timestamps --delete

上記サンプルではBitbucketのdistフォルダをデプロイ対象としている。
devlopブランチとmasterブランチで別のバケットへデプロイする想定。

経緯

公式のPipelinesのドキュメントを読んでみるとS3へのデプロイのサンプルがpythonで書かれている。
https://bitbucket.org/awslabs/amazon-s3-bitbucket-pipelines-python/
ほぼpython使ったことがないのでboto3って便利やなぁと思いながら見てみるも、ディレクトリを指定するのは面倒くさそう?と思っていたら以下の記事があったので参考にさせて頂いてawscliを使った。
boto を使って Amason S3 に指定のフォルダをアップロードするスクリプト

ミスったこと

bitbucket-pipelines.ymlのdefaultで- pip install awscliして、branchesで- aws s3 syncしようとしたが、default→branchesと順序性が保証されているわけではないみたい。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5