1
votes

I'm using codecommit, codebuild and codepipeline so that each time I commit on a branch, the associated pipeline build from codecommit in codebuild (and then deployment / invalidation)

I have 3 different scripts in my package.json called build-master, build-test & build-prod, associated to the 3 branches respectively master, test & prod.

# buildspec.yml
phases:
  install:
    commands:
    - yarn --dev
  pre_build:
    commands:
    - aws configure set preview.cloudfront true
    - bash -c 'echo "Build started `date` on bucket s3://xx.xxxxxx.$CODEBUILD_SOURCE_VERSION.web"'
  build:
    commands:
    - bash -c 'yarn build-$CODEBUILD_SOURCE_VERSION'
artifacts:
  files:
    - '**/*'
  base-directory: 'dist'
  name: xxxx-xxxx.$(date +%Y-%m-%d-%h-%M-%s).$(CODEBUILD_SOURCE_VERSION)

$CODEBUILD_SOURCE_VERSION gives me the arn of the pipeline. I've tried other variables provided by codebuild but to no avail.

I also tried to use bash -c to get the branch from git, but in codebuild I don't have access to the repo.

Is there a way to get the name of the branch with my current config ?

1
I've tried a lot of things and the only one which has worked was: stackoverflow.com/a/58408951/8650621Felipe Desiderati
You can now send Environment variables directly from CodePipeline to buildspec.yml aws.amazon.com/about-aws/whats-new/2019/10/…Shiyas

1 Answers

0
votes

You can set up a different CodeBuild project for each branch/pipeline with the environment variable(s) you want.