aws-cdk-lib.pipelines: Adding referencing construct causes "Error: Pipeline not created yet"
Describe the bug
We've wrapped pipelines.CodePipeline in our own construct, instantiate it in a stack, and then attempted to reference it by another construct.
export class PipelineStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const ahaPipeline = this.createPipeline();
this.addGithubDeploymentStatusTracking(ahaPipeline.pipeline.pipeline)
}
private createPipeline(): AhaPipeline {
const pipeline = new AhaPipeline( // construct that calls pipelines.CodePipeline
this,
`${ SERVICE_NAME }-Pipeline`,
pipelineProps,
);
...... add deployment stages ....
return pipeline;
}
private addGithubDeploymentStatusTracking(pipeline: Pipeline){
// Tracking pipeline status on github
new CodePipelinePostToGitHub(this, 'CodePipelinePostToGitHub', {
pipeline: pipeline,
githubToken: GITHUB_STATUS_TRACKING_TOKEN_SECRET_ARN,
});
}
}
Expected Behavior
Successfully compile and generate pipeline stack
Current Behavior
Received error
Error: Pipeline not created yet
at CodePipeline.get pipeline [as pipeline] (C:\Users\timmy\OneDrive\Documents\work_project\aha-nft-mgmt-service\cdk\node_modules\aws-cdk-lib\pipelines\lib\codepipeline\codepipeline.js:1:2140)
at createPipeline (C:\Users\timmy\OneDrive\Documents\work_project\aha-nft-mgmt-service\cdk\src\envs\pipeline.ts:81:50)
Reproduction Steps
- create pipeline construct
- create dependency construct that consumes cdk pipeline
- create pipeline stack with the two
will attach code example that accurately reflect our pipeline and dependency construct upon request, as it involves removing significant business logic.
Possible Solution
No response
Additional Information/Context
CodePipelinePostToGitHub is a CDKv2 port of this project, which includes an Eventbridge with lambda listener, listening on pipeline events. Lambda handler invokes Github API.
Our pipeline construct defines a multi-stage, cross account CDK pipeline.
CDK CLI Version
5.45.0 (build af1fb7c)
Framework Version
No response
Node.js Version
v16.17.0
OS
MacOS Monterey 12.5.1
Language
Typescript
Language Version
TypeScript (4.9.3)
Other information
No response
The error is occurring because another construct is trying to access CodePipeline.pipeline before the pipeline has been constructed
The pipeline isn't actually created until later in the synth stage. You can call buildPipeline() if you need the pipeline to have been internally built and constructed earlier in the app lifecycle. Does this work for you?
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
Thank you Peter, that worked!
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Hi @peterwoodworth
Asking in closed thread but,
With buildPipeline() document stated that It is not possible to modify the pipeline after calling this method.
Can you help me understand correctly but does it mean any pipeline modify after calling buildPipeline() will be ignore ?
As long as we keep changes before calling the function we are good ?
Or does it mean we can not modify the pipeline for good if we included said function into our code ? (I don't want this to happen 🦀 )
Thanks!