Skip to content

Commit 1419d2c

Browse files
committed
feat(codepipeline): add usePipelineRoleForActions field support in L2
1 parent 0c77cb6 commit 1419d2c

File tree

13 files changed

+33006
-1
lines changed

13 files changed

+33006
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import * as codebuild from 'aws-cdk-lib/aws-codebuild';
2+
import * as cdk from 'aws-cdk-lib';
3+
import * as iam from 'aws-cdk-lib/aws-iam';
4+
import * as cp from 'aws-cdk-lib/aws-codepipeline';
5+
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
6+
import * as cpactions from 'aws-cdk-lib/aws-codepipeline-actions';
7+
8+
const app = new cdk.App({
9+
postCliContext: {
10+
'@aws-cdk/pipelines:reduceStageRoleTrustScope': false,
11+
},
12+
});
13+
14+
const stack = new cdk.Stack(app, 'aws-cdk-integ-test-service-role-for-actions');
15+
const pipelineServiceRole = new iam.Role(stack, 'pipeline-role', {
16+
assumedBy: new iam.ServicePrincipal('codepipeline.amazonaws.com'),
17+
description: 'Service role for CodePipeline with CodeBuild, S3, and CodeDeploy permissions',
18+
});
19+
20+
// Add CodeBuild permissions
21+
pipelineServiceRole.addToPolicy(new iam.PolicyStatement({
22+
effect: iam.Effect.ALLOW,
23+
actions: [
24+
'codebuild:BatchGetBuilds',
25+
'codebuild:StartBuild',
26+
'codebuild:StopBuild',
27+
'codebuild:RetryBuild',
28+
],
29+
resources: ['*'],
30+
}));
31+
const inputArtifact = new cp.Artifact();
32+
const outputArtifact = new cp.Artifact();
33+
const codeStarConnection = new cdk.aws_codestarconnections.CfnConnection(stack, 'test-connection', {
34+
connectionName: 'test-connection',
35+
providerType: 'GitHub',
36+
});
37+
38+
const connectionArn = codeStarConnection.attrConnectionArn;
39+
const sourceAction = new cpactions.CodeStarConnectionsSourceAction({
40+
actionName: 'integ-action-name',
41+
output: inputArtifact,
42+
connectionArn,
43+
owner: 'cp-dev',
44+
repo: 'cp-triggers-integ-repo',
45+
});
46+
47+
new cp.Pipeline(stack, 'codepipeline-integ-trigger-test', {
48+
pipelineName: 'codepipeline-integ-trigger-test',
49+
stages: [
50+
{
51+
stageName: 'Source',
52+
actions: [sourceAction],
53+
},
54+
{
55+
stageName: 'Build',
56+
actions: [
57+
new cpactions.CodeBuildAction({
58+
actionName: 'CodeBuildAction',
59+
project: new codebuild.PipelineProject(stack, 'cp-trigger-integ-test'),
60+
input: inputArtifact,
61+
outputs: [outputArtifact],
62+
environmentVariables: {
63+
CommitId: { value: sourceAction.variables.commitId },
64+
},
65+
}),
66+
],
67+
},
68+
],
69+
});
70+
new IntegTest(app, 'codepipeline-integ-test', {
71+
testCases: [stack],
72+
stackUpdateWorkflow: false,
73+
});
74+
75+
app.synth();

0 commit comments

Comments
 (0)