Skip to content

Commit

Permalink
fix(pipelines): prevent self-mutation on asset updates (#9183)
Browse files Browse the repository at this point in the history
Currently, changes to the asset hashes of content results in changes to the
definitions of the pipeline, causing the self-mutate state to trigger. This can
cause infinite loops for systems where build artifacts change on each build.

The cause for this looping is that the asset hash was embedded as the pipeline
action name. By replacing the asset hash with a simple asset counter (already
used for the action CloudFormation id), the pipeline definition should remain
stable on asset changes.

_Testing:_ Due to the pipeline executing the current version of CDK within the
pipeline, it's impossible to actual verify that this corrects the issue. To
test + verify, created a sample app where the asset hash changed on each build.
Then ran subsequent 'cdk synth' commands and diff'ed the output. Prior to this
change, there were numerous changes related to the asset hash in the pipeline
stack. After, only the buildspec of the CodeBuild project that referenced the
hash changed. This does not change the definition of the CodePipeline itself.

fixes #9080

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
njlynch authored Jul 21, 2020
1 parent fdfed40 commit 05fc934
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/pipelines/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class AssetPublishing extends Construct {
const id = command.assetType === AssetType.FILE ? `FileAsset${this._fileAssetCtr++}` : `DockerAsset${this._dockerAssetCtr++}`;

action = this.publishers[command.assetId] = new PublishAssetsAction(this, id, {
actionName: command.assetId,
actionName: id,
cloudAssemblyInput: this.props.cloudAssemblyInput,
cdkCliVersion: this.props.cdkCliVersion,
assetType: command.assetType,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/pipelines/test/pipeline-assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test('assets are also published when using the lower-level addStackArtifactDeplo
Name: 'Assets',
Actions: [
objectLike({
Name: FILE_ASSET_SOURCE_HASH,
Name: 'FileAsset1',
RunOrder: 1,
}),
],
Expand Down

0 comments on commit 05fc934

Please sign in to comment.