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 ?
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.