pipelines: CodeBuildStep with additionalInputs fails on Windows due to default Linux install command
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
`pipelines.CodeBuildStep` with `additionalInputs` fails on Windows due to a generated bash command in the buildspec's install phase that is run in powershell.
The CDK synth and deploy works just fine, but the CodeBuild project fails with an error when the step is actually run.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Library Version
_No response_
### Expected Behavior
The defaults should work with any build image and shell combo. Therefore, using `additionalInputs` with a Windows build image should work by default.
Any generated commands should work in the chosen build image. For Windows, the default shell is powershell. But it is possible to tell it which shell to use, so it could be cmd as well. In this case, it should detect which shell is being used and add the default commands that are compatible with that shell. If it is an unsupported shell, it should log a CDK warning and not include any default commands at all.
### Current Behavior
The buildspec contains a command in the install phase that is clearly written to run in bash, but is actually executed in powershell, resulting in a syntax error and failing the step.
Here is the generated command:
```
"[ ! -d \"package-2\" ] || { echo 'additionalInputs: \"package-2\" must not exist yet. If you want to merge multiple artifacts, use a \"cp\" command.'; exit 1; } && ln -s -- \"$CODEBUILD_SRC_DIR_my_org_package_2_Source\" \"package-2\""
```
Here is the error:
```
At line:1 char:2
+ [ ! -d "package-2" ] || { echo 'additionalInputs: \"package-2\" must ...
+ ~
Missing type name after '['.
At line:1 char:22
+ [ ! -d "package-2" ] || { echo 'additionalInputs: \"package-2\" must ...
+ ~~
The token '||' is not a valid statement separator in this version.
At line:1 char:25
+ ... age-2" ] || { echo 'additionalInputs: \"package-2\" must not exist ye ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingTypename
```
NOTE: This is not the exact error since I didn't save it before working around the problem. But I just ran the command in my local powershell, which should be equivalent.
### Reproduction Steps
Given the following CDK code in TypeScript
```typescript
const input1 = pipelines.CodePipelineSource.connection(
"my-org/pacakge-1",
"main",
{
connectionArn: codestarConnectionArn,
},
);
const input2 = pipelines.CodePipelineSource.connection(
"my-org/pacakge-2",
"main",
{
connectionArn: codestarConnectionArn,
},
);
new pipelines.CodeBuildStep("Build-on-Windows", {
input: input1,
additionalInputs: {
"package-2": input2,
},
commands: ["npm run build"],
buildEnvironment: {
computeType: codebuild.ComputeType.LARGE,
buildImage: codebuild.WindowsBuildImage.WIN_SERVER_CORE_2019_BASE,
},
});
```
We get a CodeBuild project with a buildspec like this:
```json
{
"version": "0.2",
"phases": {
"install": {
"commands": [
"[ ! -d \"package-2\" ] || { echo 'additionalInputs: \"package-2\" must not exist yet. If you want to merge multiple artifacts, use a \"cp\" command.'; exit 1; } && ln -s -- \"$CODEBUILD_SRC_DIR_my_org_package_2_Source\" \"package-2\""
]
},
"build": {
"commands": [
"npm run build"
]
}
}
}
```
As you can see, the install phase has a command with the bash conditional syntax `[ ! -d "package-2" ]` which is used to check if the directory for the additional input was correctly created.
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### AWS CDK Library version (aws-cdk-lib)
2.200.1
### AWS CDK CLI version
2.1103.0 (build ba59816)
### Node.js Version
v25.5.0
### OS
MacOS 15.6.1 (24G90)
### Language
TypeScript
### Language Version
5.5.3
### Other information
I found these two issues that seem to discuss the same problem, but one is to just update the documentation and the other says it was fixed, so I believe they are different:
1. https://github.com/aws/aws-cdk/issues/30188
2. https://github.com/aws/aws-cdk/issues/17224
Contributor guide
Research direction
Start with the TypeScript CodeBuildStep example and reproduce the generated buildspec using a Windows build image with additionalInputs. Trace how the install command is generated, then add coverage for the Windows shell while preserving the existing Linux behavior; done means the generated command runs successfully in the reported configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, bash, powershell, typescript
- Domain
- build-system, cloud, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100