Skip to content

Commit

Permalink
Add proper build integration for CodePipeline
Browse files Browse the repository at this point in the history
- Now we have proper branch information (used by Coveralls) when builds
  are started via CodePiline.
    - In order to use this integration, `SOURCEVARIABLES_BRANCH_NAME`
      MUST be set to `#{SourceVariables.BranchName}`.
- Add EventBridge rule template to trigger CodePipeline on tag pushes
  (instead of the default, which is on branch pushes).
    - Note that, regardless of triggering on tag push (format `v*`),
      CodePipeline will not use this tag as source reference. It'll use
      the HEAD of branch name configured on the source stage instead.

See: thii/aws-codebuild-extras#3
  • Loading branch information
rarylson committed Nov 13, 2022
1 parent ef77b5d commit 44dab28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .codepipeline/buildspec-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ phases:
- coverage xml
post_build:
commands:
# Workaround for `CODEBUILD_SOURCE_VERSION` in batch builds
# Workarounds for `CODEBUILD_SOURCE_VERSION` in CodePipeline or batch builds
# If using CodePipeline, per convention, `SOURCEVARIABLES_BRANCH_NAME` MUST be properly set.
# See: https://github.com/thii/aws-codebuild-extras/issues/3
- |
if [ ! -z "$CODEBUILD_BATCH_BUILD_IDENTIFIER" ]; then
if [ ! -z "$SOURCEVARIABLES_BRANCH_NAME" ]; then
export CODEBUILD_SOURCE_VERSION=/refs/heads/$SOURCEVARIABLES_BRANCH_NAME
elif [ ! -z "$CODEBUILD_BATCH_BUILD_IDENTIFIER" ]; then
build_id=$(aws codebuild batch-get-builds --ids $CODEBUILD_BUILD_ID \
--query "builds[0].buildBatchArn" --output text)
source_version=$(aws codebuild batch-get-build-batches \
Expand Down
12 changes: 12 additions & 0 deletions extras/codepipeline-tuning/eventbridge-codepipeline-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"source": ["aws.codecommit"],
"detail-type": ["CodeCommit Repository State Change"],
"resources": ["arn:aws:codecommit:us-east-1:{AWS_ACCOUNT}:{REPOSITORY]"],
"detail": {
"event": ["referenceCreated", "referenceUpdated"],
"referenceType": ["tag"],
"referenceName": [{
"prefix": "v"
}]
}
}

0 comments on commit 44dab28

Please sign in to comment.