aws-cdk
aws-cdk copied to clipboard
[codepipeline] Not able to set Pipeline level environment variables.
return new codebuild.PipelineProject(this, 'Project', {
projectName: `Project`,
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
build: {
commands: ['echo ${execId}'],
},
},
}),
environment: {
buildImage: codebuild.LinuxBuildImage.STANDARD_2_0,
privileged: true,
computeType: codebuild.ComputeType.LARGE,
environmentVariables: {
execId: { value: '#{codepipeline.PipelineExecutionId}' },
},

Hey @CONJAUMCGCG ,
thanks for opening the issue. Are you running this in a CodePipeline?
Thanks, Adam
Also, this is wrong:
environment: {
buildImage: codebuild.LinuxBuildImage.STANDARD_2_0,
privileged: true,
computeType: codebuild.ComputeType.LARGE,
environmentVariables: {
execId: { value: '#{codepipeline.PipelineExecutionId}' },
},
It should be:
environment: {
buildImage: codebuild.LinuxBuildImage.STANDARD_2_0,
privileged: true,
computeType: codebuild.ComputeType.LARGE,
},
environmentVariables: {
execId: { value: '#{codepipeline.PipelineExecutionId}' },
},
@skinny85
It works, it had to be applied at StageProps level, and I was trying to apply on action level.

Glad you got it working. BTW, we actually have support for CodePipeline Variables in the CodePipeline library: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-codepipeline-readme.html#variables