forked from aws-samples/clean-code-aws-sonar-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean-code-sonar-aws-plugin.json
76 lines (76 loc) · 2.77 KB
/
clean-code-sonar-aws-plugin.json
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
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template simplifies the integration of SonarQube or SonarCloud with AWS CodeBuild and AWS CodePipeline.",
"Parameters": {
"CodeCommitRepositoryARN": {
"Type": "String",
"AllowedPattern": ".+"
},
"SonarCodeBuildProjectARN": {
"Type": "String",
"AllowedPattern": ".+"
}
},
"Resources": {
"EventBridgeCodeBuildRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "events.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"Description": "Allows EventBridge to invoke CodeBuild",
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": "codebuild:StartBuild",
"Effect": "Allow",
"Resource": { "Ref" : "SonarCodeBuildProjectARN" }
}
],
"Version": "2012-10-17"
},
"PolicyName": "AllowEventBridgeInvokeCodeBuild"
}
]
}
},
"EventRule0": {
"Type": "AWS::Events::Rule",
"Properties": {
"EventBusName": "default",
"EventPattern": {
"source": ["aws.codecommit"],
"detail-type": ["CodeCommit Pull Request State Change"],
"resources": [{ "Ref" : "CodeCommitRepositoryARN" }]
},
"Name": "OnPullRequestSonarTrigger",
"State": "ENABLED",
"Targets": [{
"Id": "SonarCodeBuildProject",
"Arn": { "Ref" : "SonarCodeBuildProjectARN" },
"RoleArn": {"Fn::GetAtt" : [ "EventBridgeCodeBuildRole", "Arn" ]},
"InputTransformer": {
"InputPathsMap": {
"sourceReference": "$.detail.sourceReference",
"PRKey": "$.detail.pullRequestId",
"DestinationBranch": "$.detail.destinationReference",
"SourceBranch": "$.detail.sourceReference"
},
"InputTemplate": "{\n \"environmentVariablesOverride\": [\n {\n \"name\": \"SOURCE_BRANCH\",\n \"type\": \"PLAINTEXT\",\n \"value\": <SourceBranch>\n },\n {\n \"name\": \"DESTINATION_BRANCH\",\n \"type\": \"PLAINTEXT\",\n \"value\": <DestinationBranch>\n },\n {\n \"name\": \"PR_KEY\",\n \"type\": \"PLAINTEXT\",\n \"value\": <PRKey>\n }\n ],\n \"sourceVersion\": <sourceReference>\n}"
}
}]
}
}
}
}