Replies: 1 comment
-
In case it helps anyone else, I set the branch name to a CodeBuild environment variable and only rely on "context" when synthesizing locally. Does seem like a workaround but maybe not.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create one set of stacks per environment based on the Git branch name. Apologies if this is more of a CodeBuild question than a CDK question. Please let me know if there is a more appropriate forum.
In "package.json" i'm populating a context variable w/ the branch name
"scripts": {
"cdk": "cdk --context branch=$(git rev-parse --abbrev-ref HEAD)"
},
The CDK generates the following static CodeBuild build command using the context variable:
npm run cdk synth --context branch=STAGE -- -o dist
When CodeBuild executes the build, setting the context variable in "package.json" takes priority over the build command resulting the following error:
throw new Error("'branch' parameter cannot be an empty string");
Creating a new "scripts" alias called "cdk-codebuild" w/o the context param, fails when attempting to retrieve the context value:
[Container] 2022/06/27 19:36:15 Running command npm run cdk-codebuild synth --context branch=STAGE -- -o dist
buildEnvironment(app.node.tryGetContext('branch').toUpperCase())
TypeError: Cannot read property 'toUpperCase' of undefined
Is there a recommended solution? Thanks
Beta Was this translation helpful? Give feedback.
All reactions