Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface CodePipelineProps {
readonly crossAccountKeys?: boolean;

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

/**
* CDK CLI version to use in asset publishing steps
*
* If you want to lock the `cdk-assets` version used in the pipeline, by steps
* that are automatically generated for you, specify the version here.
*
* We recommend you do not specify this value, as not specifying it always
* uses the latest CLI version which is backwards compatible with old versions.
*
* @see https://www.npmjs.com/package/cdk-assets
* @default - Latest version
*/
readonly cdkAssetsCliVersion?: string;

/**
* Whether the pipeline will update itself
*
Expand Down Expand Up @@ -403,6 +417,7 @@ export class CodePipeline extends PipelineBase {

private readonly singlePublisherPerAssetType: boolean;
private readonly cliVersion?: string;
private readonly cdkAssetsCliVersion: string;

constructor(scope: Construct, id: string, private readonly props: CodePipelineProps) {
super(scope, id, props);
Expand All @@ -411,6 +426,7 @@ export class CodePipeline extends PipelineBase {
this.dockerCredentials = props.dockerCredentials ?? [];
this.singlePublisherPerAssetType = !(props.publishAssetsInParallel ?? true);
this.cliVersion = props.cliVersion ?? preferredCliVersion();
this.cdkAssetsCliVersion = props.cdkAssetsCliVersion ?? 'latest';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a similar algorithm to cliVersion i.e. preferredCliVersion?

this.useChangeSets = props.useChangeSets ?? true;
this.stackOutputs = new StackOutputsMap(this);
this.usePipelineRoleForActions = props.usePipelineRoleForActions ?? false;
Expand Down Expand Up @@ -881,7 +897,7 @@ export class CodePipeline extends PipelineBase {
const script = new CodeBuildStep(node.id, {
commands,
installCommands: [
'npm install -g cdk-assets@latest',
`npm install -g cdk-assets@${this.cdkAssetsCliVersion}`,
],
input: this._cloudAssemblyFileSet,
buildEnvironment: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,32 @@ test.each([
});
});

test.each([
[undefined, 'latest'],
['9.9.9', '9.9.9'],
])('When I request cdk-assets version %p I get %p', (requested, expected) => {
const pipelineStack = new cdk.Stack(app, 'PipelineStack', { env: PIPELINE_ENV });
const pipe = new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk', {
cdkAssetsCliVersion: requested,
});

pipe.addStage(new FileAssetApp(pipelineStack, 'App', {}));

Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
Source: {
BuildSpec: Match.serializedJson(Match.objectLike({
phases: {
install: {
commands: [
`npm install -g cdk-assets@${expected}`,
],
},
},
})),
},
});
});

test('CodeBuild action role has the right AssumeRolePolicyDocument', () => {
const pipelineStack = new cdk.Stack(app, 'PipelineStack', { env: PIPELINE_ENV });
new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk');
Expand Down
Loading