-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudformation-for-codebuild-reports-with-cloudwatch-events.yaml
95 lines (95 loc) · 3.05 KB
/
cloudformation-for-codebuild-reports-with-cloudwatch-events.yaml
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
PostBuildTriggerLamda:
Description: Name of the lambda to trigger post codebuild
Type: String
Default: "post-pr-build-lambda"
Mappings:
EnvKeys:
Dev:
"CloudwatchEventRole": "arn:aws:iam::xxxxxxxxxxxx:role/CloudwatchEvent-Role"
"CodeBuildRole": "arn:aws:iam::xxxxxxxxxxxx:role/Codebuild-role"
Resources:
BuildProject:
Type: AWS::CodeBuild::Project
Properties:
Name: !Ref AWS::StackName
Description: !Ref AWS::StackName
ServiceRole: !FindInMap [EnvKeys, Dev, CodeBuildRole]
Artifacts:
Type: NO_ARTIFACTS
Environment:
Type: linuxContainer
ComputeType: BUILD_GENERAL1_LARGE
Image: aws/codebuild/standard:4.0
Source:
Type: NO_SOURCE
BuildSpec: |
version: 0.2
phases:
install:
runtime-versions:
nodejs: 10
commands:
- aws secretsmanager get-secret-value --secret-id git-oauth-token >> oAuthToken.json
- cat oAuthToken.json | jq -r '.SecretString' >> secretString.json
- githubToken="$(cat secretString.json | jq '.GitPAT' | tr -d '"')"
- git config --global credential.helper store
- echo "https://git:${githubToken}@github.com" >> ~/.git-credentials
- npm install -g ember-cli
build:
commands:
- git clone -b $BRANCH https://github.com/tamdilip/$REPO.git
- cd $REPO
- npm install
- COVERAGE=true ember test -r xunit --silent > junit.xml
finally:
- rm -f ~/.git-credentials
reports:
${REPO}-test-reports:
files:
- '*/junit.xml'
file-format: 'JUNITXML'
${REPO}-coverage-reports:
files:
- '*/coverage/*'
file-format: 'COBERTURAXML'
TimeoutInMinutes: 15
Tags:
- Key: Name
Value: !Ref AWS::StackName
EventRule:
Type: AWS::Events::Rule
Properties:
Description: "Trigger lambda on codebuild state changes"
Name: !Ref AWS::StackName
State: "ENABLED"
EventPattern:
source:
- aws.codebuild
detail-type:
- CodeBuild Build State Change
resources:
- Fn::Join:
- ":"
- - "arn:aws:codebuild"
- !Ref AWS::Region
- !Ref AWS::AccountId
- !Sub "project/${BuildProject}"
detail:
buildStatus:
- FAILED
- STOPPED
projectName:
- !Ref AWS::StackName
Targets:
- Arn:
Fn::Join:
- ":"
- - "arn:aws:lambda"
- !Ref AWS::Region
- !Ref AWS::AccountId
- "function"
- !Ref PostBuildTriggerLamda
Id: !Ref AWS::StackName
RoleArn: !FindInMap [EnvKeys, Dev, CloudwatchEventRole]