Reputation: 77
I have a CodeBuild buildspec which has command to run based on environments (reads Env. variable) eg: Dev, Test etc. I stead of creating two different codebuilds to run this command, I want to pass Env variable value from CloudWatch rules i.e. with Constant (Json).
I tried using the following but, nothing worked:
{"name":"Env-var", "value":"valueFromCWatch"}
. {"name":"Env-var", "value":"valueFromCWatch", "type":"PLAINTEXT"}
{"environmentVariables":[{"name":"Env-var", "value":"valueFromCWatch"}]}
{"environmentVariables":[{"name":"Env-var","value":"valueFromCWatch","type":"PLAINTEXT"}]}
Eg usage in BuildSpec:
- echo "Environment variable is: " `Env-var`
Is there a different way ?
Upvotes: 1
Views: 2303
Reputation: 1
I needed to add event in the code. It's more or less the same. But took me some time to figure out.
rule.addTarget(new
cdk.aws_events_targets.CodeBuildProject(codeBuildProject, {
event: cdk.aws_events.RuleTargetInput.fromObject({
environmentVariablesOverride: [
{
name: 'TAG',
value: tag,
type: 'PLAINTEXT',
},
],
}),
}));
Upvotes: 0
Reputation: 346
CodeBuild targets support all the parameters allowed by StartBuild API. You need to use environmentVariablesOverride in your JSON string.
{"environmentVariablesOverride": [
{
"name": "Envvar",
"value": "valueFromCWatch"
}
]}
Also, avoid using '-' in the environment name.
Upvotes: 3