Skip to content

Commit

Permalink
fix(codepipeline-actions): EcrSourceAction triggers on a push to ever…
Browse files Browse the repository at this point in the history
…y tag (#13822)

The EcrSourceAction was incorrectly being triggered on a push of every tag if the `imageTag`
property was not provided, instead of defaulting to 'latest',
like its documentation suggested.

Correct the error by passing 'latest' to the created CloudWatch Event if `imageTag` was not set.

Fixes #13818

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
skinny85 authored Apr 2, 2021
1 parent 24f8307 commit c5a2add
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class EcrSourceAction extends Action {

this.props.repository.onCloudTrailImagePushed(Names.nodeUniqueId(stage.pipeline.node) + 'SourceEventRule', {
target: new targets.CodePipeline(stage.pipeline),
imageTag: this.props.imageTag,
imageTag: this.props.imageTag ?? 'latest',
});

// the Action Role also needs to write to the Pipeline's bucket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@
},
"MyEcrRepo767466D0": {
"Type": "AWS::ECR::Repository",
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"MyEcrRepoawscdkcodepipelineecrsourceMyPipeline63CF3194SourceEventRule911FDB6D": {
"Type": "AWS::Events::Rule",
Expand All @@ -367,6 +367,9 @@
{
"Ref": "MyEcrRepo767466D0"
}
],
"imageTag": [
"latest"
]
},
"eventName": [
Expand Down Expand Up @@ -412,4 +415,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const pipeline = new codepipeline.Pipeline(stack, 'MyPipeline', {
artifactBucket: bucket,
});

const repository = new ecr.Repository(stack, 'MyEcrRepo');
const repository = new ecr.Repository(stack, 'MyEcrRepo', {
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const sourceStage = pipeline.addStage({ stageName: 'Source' });
sourceStage.addAction(new cpactions.EcrSourceAction({
actionName: 'ECR_Source',
Expand Down

0 comments on commit c5a2add

Please sign in to comment.