(assets): Allow using exported variables from Assets stage steps
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 71
Description
### Describe the feature
Way to refer to variables in latter CodePipeline steps that are exported from Assets stage's steps.
### Use Case
This would speed up pipeline run quite a lot, when we can do container security scanning in Asset stage (which is already possible) and get the ID of the scan to be included in latter created documents about the builds.
We can export the value as it's doable in partialBuildSpec, but we can't refer that in latter steps as Asset stage steps doesn't have namespace set.
We can dynamically get the asset steps that build docker images in Synth step with jq and exported variables.
```
export ASSET_STAGES_EXPORTED_IDS=$(jq -r 'map(.. | select(.Name? and .Name=="Assets") | .Actions[].Name | select(test("DockerAsset.*")) | "#{Assets@\\(.).EXPORTED_SCAN_ID}") | join(",")' cdk.out/${pipelineStackName}.template.json)`,
```
If there would even be static namespace (in example `Assets`, it would be possible to use those value later).
### Proposed Solution
Export Asset steps' CodeBuildSteps same way as Synth has those exposed so that it's possible to use variable referencing from steps in Asset stage. Kind of issue here could be that it would also require calculation of amount of needed asset steps earlier than now.
Other option would be just hardcode the namespace also to Asset stage steps so exported values from those could manually be referred. If namespace would be as in other `Asset@DockerAsset1` etc., still above used way to get the needed steps would be needed. But this would still work.
### Other Information
We have CodeBuild projects that CDK created CodePipeline uses deployed to our custom VPC, meaning that provisioning time is minimum around 90 seconds. We also do security scanning of the built image, and image is created at the Asset stage.
### Acknowledgements
- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.20.0
### Environment details (OS name and version, etc.)
Debian bullseye
Contributor guide
Research direction
Start by tracing how Synth exposes CodeBuildSteps and how Assets stage steps are generated, including the partialBuildSpec and namespace handling described in the issue. Compare the proposed exported-step approach with assigning a static namespace, and verify that later CodePipeline steps can reference the exported values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- ci-cd
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100