-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
integ.pipeline-with-pipeline-triggers.ts
123 lines (112 loc) · 3.96 KB
/
integ.pipeline-with-pipeline-triggers.ts
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import * as codebuild from 'aws-cdk-lib/aws-codebuild';
import * as codepipeline from 'aws-cdk-lib/aws-codepipeline';
import * as cdk from 'aws-cdk-lib';
import * as cpactions from 'aws-cdk-lib/aws-codepipeline-actions';
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-cdk-codepipeline-with-pipeline-triggers');
// Make sure you specify a valid connection ARN.
const connectionArn = process.env.CONNECTION_ARN || 'MOCK';
if (connectionArn === 'MOCK') {
cdk.Annotations.of(stack).addWarningV2('integ:connection-arn', 'You must specify a valid connection ARN in the CONNECTION_ARN environment variable');
}
const sourceOutput1 = new codepipeline.Artifact();
const sourceAction1 = new cpactions.CodeStarConnectionsSourceAction({
actionName: 'CodeStarConnectionsSourceAction',
output: sourceOutput1,
connectionArn,
owner: 'go-to-k',
repo: 'cdk-codepipeline-demo-1',
});
// for push filter with tags
new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineName: 'my-pipeline',
pipelineType: codepipeline.PipelineType.V2,
crossAccountKeys: true,
stages: [
{
stageName: 'Source',
actions: [sourceAction1],
},
{
stageName: 'Build',
actions: [
new cpactions.CodeBuildAction({
actionName: 'CodeBuild',
project: new codebuild.PipelineProject(stack, 'MyProject'),
input: sourceOutput1,
outputs: [new codepipeline.Artifact()],
environmentVariables: {
CommitId: { value: sourceAction1.variables.commitId },
},
}),
],
},
],
triggers: [{
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
gitConfiguration: {
sourceAction: sourceAction1,
pushFilter: [{
tagsExcludes: ['exclude1', 'exclude2'],
tagsIncludes: ['include1', 'include2'],
}],
},
}],
});
const sourceOutput2 = new codepipeline.Artifact();
const sourceAction2 = new cpactions.CodeStarConnectionsSourceAction({
actionName: 'CodeStarConnectionsSourceAction2',
output: sourceOutput2,
connectionArn,
owner: 'go-to-k',
repo: 'cdk-codepipeline-demo-2',
});
// for pull request filter with branches and file paths
new codepipeline.Pipeline(stack, 'Pipeline2', {
pipelineName: 'my-pipeline2',
pipelineType: codepipeline.PipelineType.V2,
crossAccountKeys: true,
stages: [
{
stageName: 'Source',
actions: [sourceAction2],
},
{
stageName: 'Build',
actions: [
new cpactions.CodeBuildAction({
actionName: 'CodeBuild2',
project: new codebuild.PipelineProject(stack, 'MyProject2'),
input: sourceOutput2,
outputs: [new codepipeline.Artifact()],
environmentVariables: {
CommitId: { value: sourceAction2.variables.commitId },
},
}),
],
},
],
triggers: [{
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
gitConfiguration: {
sourceAction: sourceAction2,
pullRequestFilter: [{
branchesExcludes: ['exclude1', 'exclude2'],
branchesIncludes: ['include1', 'include2'],
filePathsExcludes: ['/path/to/exclude1', '/path/to/exclude2'],
filePathsIncludes: ['/path/to/include1', '/path/to/include2'],
events: [codepipeline.GitPullRequestEvent.OPEN, codepipeline.GitPullRequestEvent.UPDATED],
}],
},
}],
});
const integrationTest = new IntegTest(app, 'codepipeline-with-pipeline-triggers-test', {
testCases: [stack],
diffAssets: true,
});
const awsApiCall1 = integrationTest.assertions.awsApiCall('CodePipeline', 'getPipeline', { name: 'my-pipeline' });
awsApiCall1.assertAtPath('pipeline.name', ExpectedResult.stringLikeRegexp('my-pipeline'));
const awsApiCall2 = integrationTest.assertions.awsApiCall('CodePipeline', 'getPipeline', { name: 'my-pipeline2' });
awsApiCall2.assertAtPath('pipeline.name', ExpectedResult.stringLikeRegexp('my-pipeline2'));
app.synth();