Skip to content

Commit a361c9c

Browse files
authored
feat(pipelines): cdk-assets version is configurable (#34802)
Make it possible to configure the version of `cdk-assets` CLI used by the CDK Pipeline. This is only useful for versions of `cdk-assets` *newer*` than `3.3.1`, as older versions have wildcard ranges in their transitive dependencies and may install different versions of packages depending on what is currently available on npmjs.com. The first `cdk-assets` version after `3.3.1` will bundle its dependencies so that the install operation will be deterministic. We recommend you don't use this feature and just leave it at `latest`. The bundling of dependencies of `cdk-assets` will already remove any install failures around the release time of a new SDKv3 version, that used to plague `cdk-assets` in the past. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c5983b1 commit a361c9c

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export interface CodePipelineProps {
7575
readonly crossAccountKeys?: boolean;
7676

7777
/**
78-
* CDK CLI version to use in self-mutation and asset publishing steps
78+
* CDK CLI version to use in self-mutation step
7979
*
8080
* If you want to lock the CDK CLI version used in the pipeline, by steps
8181
* that are automatically generated for you, specify the version here.
@@ -97,6 +97,20 @@ export interface CodePipelineProps {
9797
*/
9898
readonly cliVersion?: string;
9999

100+
/**
101+
* CDK CLI version to use in asset publishing steps
102+
*
103+
* If you want to lock the `cdk-assets` version used in the pipeline, by steps
104+
* that are automatically generated for you, specify the version here.
105+
*
106+
* We recommend you do not specify this value, as not specifying it always
107+
* uses the latest CLI version which is backwards compatible with old versions.
108+
*
109+
* @see https://www.npmjs.com/package/cdk-assets
110+
* @default - Latest version
111+
*/
112+
readonly cdkAssetsCliVersion?: string;
113+
100114
/**
101115
* Whether the pipeline will update itself
102116
*
@@ -403,6 +417,7 @@ export class CodePipeline extends PipelineBase {
403417

404418
private readonly singlePublisherPerAssetType: boolean;
405419
private readonly cliVersion?: string;
420+
private readonly cdkAssetsCliVersion: string;
406421

407422
constructor(scope: Construct, id: string, private readonly props: CodePipelineProps) {
408423
super(scope, id, props);
@@ -411,6 +426,7 @@ export class CodePipeline extends PipelineBase {
411426
this.dockerCredentials = props.dockerCredentials ?? [];
412427
this.singlePublisherPerAssetType = !(props.publishAssetsInParallel ?? true);
413428
this.cliVersion = props.cliVersion ?? preferredCliVersion();
429+
this.cdkAssetsCliVersion = props.cdkAssetsCliVersion ?? 'latest';
414430
this.useChangeSets = props.useChangeSets ?? true;
415431
this.stackOutputs = new StackOutputsMap(this);
416432
this.usePipelineRoleForActions = props.usePipelineRoleForActions ?? false;
@@ -881,7 +897,7 @@ export class CodePipeline extends PipelineBase {
881897
const script = new CodeBuildStep(node.id, {
882898
commands,
883899
installCommands: [
884-
'npm install -g cdk-assets@latest',
900+
`npm install -g cdk-assets@${this.cdkAssetsCliVersion}`,
885901
],
886902
input: this._cloudAssemblyFileSet,
887903
buildEnvironment: {

packages/aws-cdk-lib/pipelines/test/codepipeline/codepipeline.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,32 @@ test.each([
210210
});
211211
});
212212

213+
test.each([
214+
[undefined, 'latest'],
215+
['9.9.9', '9.9.9'],
216+
])('When I request cdk-assets version %p I get %p', (requested, expected) => {
217+
const pipelineStack = new cdk.Stack(app, 'PipelineStack', { env: PIPELINE_ENV });
218+
const pipe = new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk', {
219+
cdkAssetsCliVersion: requested,
220+
});
221+
222+
pipe.addStage(new FileAssetApp(pipelineStack, 'App', {}));
223+
224+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
225+
Source: {
226+
BuildSpec: Match.serializedJson(Match.objectLike({
227+
phases: {
228+
install: {
229+
commands: [
230+
`npm install -g cdk-assets@${expected}`,
231+
],
232+
},
233+
},
234+
})),
235+
},
236+
});
237+
});
238+
213239
test('CodeBuild action role has the right AssumeRolePolicyDocument', () => {
214240
const pipelineStack = new cdk.Stack(app, 'PipelineStack', { env: PIPELINE_ENV });
215241
new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk');

0 commit comments

Comments
 (0)