Skip to content

(pipelines): Add ability to specify Codepipeline variable namespace on CodePipelineSource classes. #16407

@dax-hurley

Description

@dax-hurley

I would like to be able to specify the CodePipeline variable namespace, and/or access the variable properties of the underlying action constructs for CodePipline source classes and potentially the other Step classes.

Use Case

I am looking to implement automated semantic versioning of my private NPM package using CDK pipelines for CI/CD and the standard-version NPM package. To support this use-case I would like to use bash in CodeBuild to conditionally determine whether to publish the package based off commit message, as below:

if [[ $COMMIT_MESSAGE == "chore(release):"* ]]; then npm publish; fi

In order to do this I obviously have to make the commit message available to CodeBuild since it isn't by default. The most obvious way to do this was via CodePipeline variables and I was disappointed to find that the higher level APIs of CDK Pipelines do not provide a way to access them.

Proposed Solution

One approach would be to allow specifying the the namespace when creating the CodePipelineSource object by specifying it in the props as in:

sourceInput = CodePipelineSource.codeCommit(
  /* ... */
  {
    variablesNamespace: "SourceVariables",
  }
);

const pipeline = new CodePipeline(this, `${id}PipelineResource`, {
  synth: new SynthStep(/* ... */),
  codeBuildDefaults: {
    buildEnvironment: {
      environmentVariables: {
        COMMIT_MESSAGE: {
          type: BuildEnvironmentVariableType.PLAINTEXT,
          value: "#{SourceVariables.CommitMessage}",
        },
      },
    },
  },
  /* ... */
});

An alternative approach would be to allow users to access the variable properties of the underlying action, e.g:

sourceInput = CodePipelineSource.codeCommit( /* ... */ );

const pipeline = new CodePipeline(this, `${id}PipelineResource`, {
  synth: new SynthStep(/* ... */),
  codeBuildDefaults: {
    buildEnvironment: {
      environmentVariables: {
        COMMIT_MESSAGE: {
          type: BuildEnvironmentVariableType.PLAINTEXT,
          value: sourceAction.variables.commitMessage,
        },
      },
    },
  },
  /* ... */
});

My use case requires this feature to be implemented on the child classes of CodePipelineSource, but for consistency it should probably be added to all relevant Step classes (those whose actions allow you to specify namespace).

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/pipelinesCDK Pipelines libraryeffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions