CDK pipeline won’t restart after mutation

CDK Pipeline is a clever construct that makes continuously deploying your application and infrastructure super easy. The pipeline even has the ability to update itself or “mutate” if your commits include changes to the pipeline itself. This behavior is controlled by selfMutation property of the pipeline constructor and is true by default. Once the pipeline updates itself – it also restarts itself, so that new changes can take effect.

But if you create your CDK pipeline with regular AWS Pipeline as a base e.g.

const rawPipeline = new Pipeline(this, 'RawPipeline', {
   ...
 });
 
const pipeline = new CodePipeline(this, 'Pipeline', {
   codePipeline: rawPipeline,
   ...
});

suddenly the pipeline won’t auto-restart after the mutation. What is happening?

The regular AWS Pipeline that is used under the hood in the CDK CodePipeline has restartExecutionOnUpdate property that controls whether the pipeline is restarted after it was updated. When you let the CDK CodePipeline create the base pipeline automatically – it sets that property to true. But, if you create the base pipeline yourself – like in the example above – restartExecutionOnUpdate is false by default, so you have to set it to true:

const rawPipeline = new Pipeline(this, 'RawPipeline', {
   restartExecutionOnUpdate: true
   ...
 });
 
const pipeline = new CodePipeline(this, 'Pipeline', {
   codePipeline: rawPipeline,
   ...
});

With this option set – pipeline behaves as expected – after it self-mutates it restarts.

Leave a Reply

Your email address will not be published. Required fields are marked *