Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codepipeline): cannot trigger on all tags anymore in EcrSourceAction #17270

Merged
merged 10 commits into from
Nov 25, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface EcrSourceVariables {
export interface EcrSourceActionProps extends codepipeline.CommonAwsActionProps {
/**
* The image tag that will be checked for changes.
* Provide an empty string to trigger on changes to any tag.
*
* @default 'latest'
*/
Expand Down Expand Up @@ -95,7 +96,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 ?? 'latest',
imageTag: this.props.imageTag === '' ? undefined : (this.props.imageTag ?? 'latest'),
});

// the Action Role also needs to write to the Pipeline's bucket
Expand All @@ -104,7 +105,7 @@ export class EcrSourceAction extends Action {
return {
configuration: {
RepositoryName: this.props.repository.repositoryName,
ImageTag: this.props.imageTag,
ImageTag: this.props.imageTag ? this.props.imageTag : undefined, // `''` is falsy in JS/TS
},
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '@aws-cdk/assert-internal/jest';
import { ABSENT } from '@aws-cdk/assert-internal';
import * as codebuild from '@aws-cdk/aws-codebuild';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as ecr from '@aws-cdk/aws-ecr';
Expand Down Expand Up @@ -60,6 +61,78 @@ describe('ecr source action', () => {
});


expect(stack).toHaveResourceLike('AWS::Events::Rule', {
'EventPattern': {
'detail': {
'requestParameters': {
'imageTag': ['latest'],
},
},
},
});
});

test('watches all tags when imageTag provided as empty string', () => {
const stack = new Stack();

const sourceOutput = new codepipeline.Artifact();
const ecrSourceAction = new cpactions.EcrSourceAction({
actionName: 'Source',
output: sourceOutput,
repository: ecr.Repository.fromRepositoryName(stack, 'Repo', 'repo'),
imageTag: '',
});

new codepipeline.Pipeline(stack, 'Pipeline', {
stages: [
{
stageName: 'Source',
actions: [ecrSourceAction],
},
{
stageName: 'Build',
actions: [
new cpactions.CodeBuildAction({
actionName: 'Build',
project: new codebuild.PipelineProject(stack, 'MyProject'),
input: sourceOutput,
environmentVariables: {
ImageDigest: { value: ecrSourceAction.variables.imageDigest },
},
}),
],
},
],
});

expect(stack).toHaveResourceLike('AWS::Events::Rule', {
'EventPattern': {
'source': [
'aws.ecr',
],
'detail': {
'requestParameters': {
'imageTag': ABSENT,
},
},
},
});
sparten11740 marked this conversation as resolved.
Show resolved Hide resolved

expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
'Stages': [
{
'Name': 'Source',
'Actions': [
{
'Name': 'Source',
'Configuration': {
'ImageTag': ABSENT,
},
},
],
},
],
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,4 @@
}
}
}
}
}