aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

[codepipeline] Not able to set Pipeline level environment variables.

Open CONJAUMCGCG opened this issue 6 years ago • 4 comments

    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}' },
      },

image

CONJAUMCGCG avatar Aug 20 '20 01:08 CONJAUMCGCG

Hey @CONJAUMCGCG ,

thanks for opening the issue. Are you running this in a CodePipeline?

Thanks, Adam

skinny85 avatar Aug 31 '20 15:08 skinny85

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 avatar Aug 31 '20 15:08 skinny85

@skinny85 It works, it had to be applied at StageProps level, and I was trying to apply on action level. image

CONJAUMCGCG avatar Aug 31 '20 16:08 CONJAUMCGCG

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

skinny85 avatar Aug 31 '20 21:08 skinny85