creating cdk pipeline but it deletes itself

0

hello,

I am trying to create a simple pipeline from udemy and at first its fine I even saw that the pipeline was being created and when it was almost complete i got a pipeline not found

here is my code

import * as cdk from 'aws-cdk-lib';
import { CodePipeline, CodePipelineSource, ShellStep } from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';

export class CdkCicdStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new CodePipeline(this, 'AwesomePipeline', {
      pipelineName: 'AwesomePipeline',
      synth: new ShellStep('Synth', {
        input: CodePipelineSource.gitHub('jameseraynor/cdk-cicd', 'main'),
        commands: [
          'npm ci',
          'npx cdk synth'
        ],
      })
    })
  }
}

and

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { CdkCicdStack } from '../lib/cdk-cicd-stack';

const app = new cdk.App();
new CdkCicdStack(app, 'CdkCicdStack', {
});

app.synth();

error while watching being created and deleted Enter image description here

the unexpected actions of cleanup Enter image description here

2 Answers
0
Accepted Answer

for completeness. I asked in stackoverflow and the solution was to upload the code first to the repo and then run deploy. the explanation given was that since the pipeline didn't see any code in the repo in the first place there was nothing for the pipeline to stay active.

answered 13 days ago
0

The issue you're experiencing with your CDK pipeline deleting itself is likely due to the self-mutating nature of CDK pipelines. By default, CDK pipelines are designed to be self-mutating, which means they can update themselves. However, in some cases, this can lead to unexpected behavior like the pipeline deleting itself.

To resolve this issue, you need to make a few modifications to your code:

  1. Add a selfMutation property to your pipeline configuration:
new CodePipeline(this, 'AwesomePipeline', {
  pipelineName: 'AwesomePipeline',
  selfMutation: true,
  synth: new ShellStep('Synth', {
    input: CodePipelineSource.gitHub('jameseraynor/cdk-cicd', 'main'),
    commands: [
      'npm ci',
      'npx cdk synth'
    ],
  })
})
  1. Ensure that you have the necessary permissions for the pipeline to update itself. You may need to add an IAM policy to allow the pipeline to modify its own resources.

  2. If you're using Docker image assets in your pipeline, you should also enable Docker for self-mutation:

new CodePipeline(this, 'AwesomePipeline', {
  pipelineName: 'AwesomePipeline',
  selfMutation: true,
  dockerEnabledForSelfMutation: true,
  synth: new ShellStep('Synth', {
    input: CodePipelineSource.gitHub('jameseraynor/cdk-cicd', 'main'),
    commands: [
      'npm ci',
      'npx cdk synth'
    ],
  })
})
  1. Make sure your GitHub repository is properly connected and the pipeline has the necessary permissions to access it.

  2. Double-check that your CDK version is up-to-date, as older versions might have issues with self-mutating pipelines.

By making these changes, you should be able to create a stable, self-mutating pipeline that doesn't delete itself unexpectedly. If you continue to experience issues, you may need to investigate your IAM permissions and ensure that the pipeline has the correct access to modify its own resources.
Sources
interface CodeBuildStepProps · AWS CDK
interface BuildEnvironment · AWS CDK

profile picture
answered 14 days ago
  • 1- I have tried adding the mutated line and still fails 2- i dont understand this, the pipeline is already creating itself and deleting itself 3- not using docker 4- i have created a new token again and validated the it has the repo and admin hook rights. and i have updated it in the secrets manager 5- confirmed I have the latest version of CDK (2.1012.0 (build e4c1f15) )

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions