-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildspec.yml
34 lines (33 loc) · 1.85 KB
/
buildspec.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
version: 0.2
# env:
# git-credential-helper: yes
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
- export PIPELINE_NAME=`echo $CODEBUILD_INITIATOR | cut -c14-`
- export ID=$(aws codepipeline get-pipeline-state --region $AWS_DEFAULT_REGION --name $PIPELINE_NAME --query 'stageStates[?actionStates[?latestExecution.externalExecutionId==`'${CODEBUILD_BUILD_ID}'`]].latestExecution.pipelineExecutionId' --output text)
- export TRIGGER=$(aws codepipeline list-pipeline-executions --pipeline $PIPELINE_NAME | jq -r ".pipelineExecutionSummaries[]|select(.pipelineExecutionId==\"$ID\")|.trigger.triggerType")
- export LAST_SUCCESSFUL_COMMIT_ID=$(aws codepipeline list-pipeline-executions --pipeline-name $PIPELINE_NAME | jq -r '[.pipelineExecutionSummaries[] | select(.status == "Succeeded") | .sourceRevisions[0].revisionId][0]')
- echo Trigger is $TRIGGER, not Webhook means build all
build:
commands:
- echo Build started on `date`
- IMAGE_TAG=test
- branch=`echo $CODEBUILD_INITIATOR | awk -F'-' '{ print $NF }'`
- if [ -n "$branch" ]; then IMAGE_TAG=$branch; fi
- export IMAGE_TAG
- bash build_and_update.sh $TRIGGER all
post_build:
commands:
# Update version file on S3
- echo Updating build commit in s3://$WEB_BUCKET_NAME/$IMAGE_TAG-info/$VERSION_PATH
- #aws s3 cp s3://$WEB_BUCKET_NAME/$IMAGE_TAG-info/$VERSION_PATH versions.json
- cat versions.json
- cat versions.json | jq --arg commit "$CODEBUILD_RESOLVED_SOURCE_VERSION" '.aws|="\($commit)"' > versions.tmp
- mv versions.tmp versions.json
- cat versions.json
- aws s3 cp versions.json s3://$WEB_BUCKET_NAME/$IMAGE_TAG-info/$VERSION_PATH
# Complete the build
- echo Build completed on `date`