[Codepipelines] Passing CodeBuild generated parameters into Codepipelines ApplicationStage with CDK
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
I have a Codepipelines based project (v. 1.114.0).
Use case:
I need to deploy an application stack to multiple environments, and want to input a build number that is the output of the build stage in the pipeline. The build number references the docker build in ECR that I want the application stack to use. To this end, I am attempting to pass the build number parameter generated at build time in a CodeBuild stage to the ApplicationStage deployment in Cloudformation.
Code:
```ts
// Pipeline
const pipeline = new pipelines.CdkPipeline(this, 'Pipeline', {...});
// Build stage
const buildStage = pipeline.addStage('Build')
const buildOutput = new codepipeline.Artifact();
const buildAction = new actions.CodeBuildAction({
...
buildSpec: codebuild.BuildSpec.fromSourceFilename("buildspec.yml")
}),
// I create a JSON artifact containing the data I want in the artifact
outputs: [buildOutput]
});
buildStage.addActions(buildAction);
// Application stage
const stage = new ApplicationStage(this, "ApplicationStage", {
env: {
account: ,
region:
},
...
outputData: buildOutput.getParam("output_file", "output_key")
});
pipeline.addApplicationStage(stage);
// My stage class which is instantiated above
class ApplicationStage extends cdk.Stage {
constructor(scope: cdk.Construct, id: string, props: ApplicationStageProps) {
super(scope, id, props);
// Create a stack which uses the data
new MyStack(this, "MyStack", {data: props.outputData});
};
}
```
I am seeing errors in CFN when attempting to deploy the application stack:
Template Error: Encountered unsupported function: Fn::GetArtifactAtt Supported functions are: [Fn::Base64, Fn::GetAtt,
Fn::GetAZs, Fn::ImportValue, Fn::Join, Fn::Split, Fn::FindInMap, Fn::Select, Ref, Fn::Equals, Fn::If, Fn::Not, Condition,
Fn::And, Fn::Or, Fn::Contains, Fn::EachMemberEquals, Fn::EachMemberIn, Fn::ValueOf, Fn::ValueOfAll, Fn::RefAll, Fn::Sub,
Fn::Cidr] (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: ; Proxy: null)
I have already tried to pass this information using Codepipelines variables that I exported from CodeBuild, but with no luck (CFN is unable to resolve variable references cross stage it seems). Additionally, the cdk.Stage construct does not support parameter overrides as far as I can tell.
Any recommendations for how to pull this off? It seems like there is not support for this use case.
P.S. Would prefer not to use Parameter Store as I have multiple deployment stages and want to ensure the specific build output is passed to the correct stage at the correct time. While this is likely doable with the Parameter Store, it introduces unnecessary complexity.
Contributor guide
Research direction
Start by reviewing the CDK pipeline and ApplicationStage APIs involved in the example, especially CodeBuildAction outputs and artifact parameter handling. Reproduce the CloudFormation Fn::GetArtifactAtt error with the stated setup, then determine whether a supported cross-stage value-passing mechanism exists; done means a validated approach or a clearly documented limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- ci-cd, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100