From 3fa97c34a816bb2464ee2574667edbe4417c18b9 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 6 Oct 2020 13:16:24 +0200 Subject: [PATCH] fix(pipelines): pipeline doesn't restart if CLI version changes To fix, add the CLI version into the pipeline structure (as an environment variable to the CodePipeline project). Fixes #10659. --- .../lib/actions/publish-assets-action.ts | 4 +++ .../lib/actions/update-pipeline-action.ts | 4 +++ .../@aws-cdk/pipelines/test/pipeline.test.ts | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/packages/@aws-cdk/pipelines/lib/actions/publish-assets-action.ts b/packages/@aws-cdk/pipelines/lib/actions/publish-assets-action.ts index 7e8b46b7a4503..1e2adadafb52d 100644 --- a/packages/@aws-cdk/pipelines/lib/actions/publish-assets-action.ts +++ b/packages/@aws-cdk/pipelines/lib/actions/publish-assets-action.ts @@ -137,6 +137,10 @@ export class PublishAssetsAction extends CoreConstruct implements codepipeline.I project, input: this.props.cloudAssemblyInput, role: props.role, + // Add this purely so that the pipeline will selfupdate if the CLI version changes + environmentVariables: props.cdkCliVersion ? { + CDK_CLI_VERSION: { value: props.cdkCliVersion }, + } : undefined, }); } diff --git a/packages/@aws-cdk/pipelines/lib/actions/update-pipeline-action.ts b/packages/@aws-cdk/pipelines/lib/actions/update-pipeline-action.ts index 9642fa7ba854e..20dce58246c27 100644 --- a/packages/@aws-cdk/pipelines/lib/actions/update-pipeline-action.ts +++ b/packages/@aws-cdk/pipelines/lib/actions/update-pipeline-action.ts @@ -93,6 +93,10 @@ export class UpdatePipelineAction extends CoreConstruct implements codepipeline. actionName: 'SelfMutate', input: props.cloudAssemblyInput, project: selfMutationProject, + // Add this purely so that the pipeline will selfupdate if the CLI version changes + environmentVariables: props.cdkCliVersion ? { + CDK_CLI_VERSION: { value: props.cdkCliVersion }, + } : undefined, }); } diff --git a/packages/@aws-cdk/pipelines/test/pipeline.test.ts b/packages/@aws-cdk/pipelines/test/pipeline.test.ts index 8fa56d50f3ea0..023f4bdcf575d 100644 --- a/packages/@aws-cdk/pipelines/test/pipeline.test.ts +++ b/packages/@aws-cdk/pipelines/test/pipeline.test.ts @@ -385,6 +385,33 @@ test('can control fix/CLI version used in pipeline selfupdate', () => { }); }); +test('changing CLI version leads to a different pipeline structure (restarting it)', () => { + // GIVEN + const stack2 = new Stack(app, 'Stack2', { env: PIPELINE_ENV }); + const stack3 = new Stack(app, 'Stack3', { env: PIPELINE_ENV }); + const structure2 = Capture.anyType(); + const structure3 = Capture.anyType(); + + // WHEN + new TestGitHubNpmPipeline(stack2, 'Cdk', { + cdkCliVersion: '1.2.3', + }); + new TestGitHubNpmPipeline(stack3, 'Cdk', { + cdkCliVersion: '4.5.6', + }); + + // THEN + expect(stack2).toHaveResourceLike('AWS::CodePipeline::Pipeline', { + Stages: structure2.capture(), + }); + expect(stack3).toHaveResourceLike('AWS::CodePipeline::Pipeline', { + Stages: structure3.capture(), + }); + + expect(JSON.stringify(structure2.capturedValue)).not.toEqual(JSON.stringify(structure3.capturedValue)); + +}); + test('add another action to an existing stage', () => { // WHEN pipeline.stage('Source').addAction(new cpa.GitHubSourceAction({