(pipelines): FileSets rendering of `cdk.out` artifacts conflicts with artifacts codebuild partial
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
The `pipelines` module in the `CodePipeline` construct, when setup to be self-mutating, takes any `primary_output_directory` property defined for the synth `ShellStep` as well as any additional output directories added, and renders into a codebuild `artifacts:` partial section. If the construct user adds an `artifacts:` partial to codebuild options to the `CodePipeline` constructor (`code_build_defaults` or `synth_code_build_defaults`) then it is rendered with 2 `artifacts:` sections in the buildspec defined for the `CodeBuild` resource. This results in a jsii synth error of `jsii.errors.JSIIError: Error: Only one build spec is allowed to specify artifacts.`
Example result
```
artifacts:
secondary-artifacts:
dist:
base-directory: dist
files:
- "**/*"
artifacts:
base-directory: cdk.out
files:
**/*
```
### Expected Behavior
I would expect some sort of hash merge to occur between FileSets defined for the ShellStep (whether default added `cdk.out` directory or something custom from the library user) as well as any `artifacts:` section in any codebuild partials in play.
### Current Behavior
Currently two `artifacts:` hashes exist in the same rendered codebuild partial and jsii is choking on it.
### Reproduction Steps
```
synth_code_build_defaults = pipelines.CodeBuildOptions(
partial_build_spec=codebuild.BuildSpec.from_object({"artifacts":{
"secondary-artifacts":{"dist":{"base-directory":"dist","files":["**/*"]} } } })
)
synth_shell_step = pipelines.ShellStep(
"Synth",
input=pipelines.CodePipelineSource.connection(redacted),
install_commands=["./install.sh"],
commands=["./build.sh"]
)
pipeline=pipelines.CodePipeline(
self,
"Pipeline",
pipeline_name="test-Pipeline",
synth=synth_shell_step,
synth_code_build_defaults=synth_code_build_defaults,
)
pipeline.build_pipeline()
```
and synth should fail with `jsii.errors.JSIIError: Error: Only one build spec is allowed to specify artifacts.`
### Possible Solution
I tried to dig into how `pipelines/codepipeline.ts` is handling artifacts (and how that relates to `aws-codepipeline/pipeline.ts` and really wasn't able to.
### Additional Information/Context
_No response_
### CDK CLI Version
2.43.0 (build 487870a)
### Framework Version
_No response_
### Node.js Version
v14.17.0
### OS
Linux
### Language
Python
### Language Version
Python 3.8.5
### Other information
_No response_
Contributor guide
Research direction
Start by reading pipelines/codepipeline.ts and then the related aws-codepipeline/pipeline.ts handling of CodeBuild partials and FileSets. Reproduce the Python example with synth_code_build_defaults and a ShellStep, then verify that the rendered buildspec contains one merged artifacts section and no jsii error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100