Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 2 tasks
dax-hurley opened this issue Sep 8, 2021 · 2 comments · Fixed by #19024
Closed
1 of 2 tasks
Labels
@aws-cdk/pipelines CDK Pipelines library effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1

Comments

@dax-hurley
Copy link

dax-hurley commented Sep 8, 2021

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

@dax-hurley dax-hurley added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 8, 2021
@github-actions github-actions bot added @aws-cdk/aws-codepipeline Related to AWS CodePipeline @aws-cdk/pipelines CDK Pipelines library labels Sep 8, 2021
@dax-hurley
Copy link
Author

Looking through existing PRs I found #15964 and the related issue #15943. While the other issue and PR are specifically related to the CodebuildStep class, meaning I don't believe my issue would be considered a duplicate, they do indicate that the current favored direction for the implementation of this feature would the use of a method called variable that takes a variable name and returns the Codepipeline variable reference syntax, so changing my example to this approach it could look like:

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

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

@rix0rrr rix0rrr added effort/medium Medium work item – several days of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 17, 2021
@rix0rrr rix0rrr removed their assignment Sep 17, 2021
@skinny85 skinny85 assigned rix0rrr and unassigned skinny85 Sep 22, 2021
@skinny85 skinny85 removed the @aws-cdk/aws-codepipeline Related to AWS CodePipeline label Sep 22, 2021
@rix0rrr rix0rrr removed their assignment Oct 4, 2021
rix0rrr added a commit that referenced this issue Feb 17, 2022
feat(pipelines): step outputs

Make it possible to export environment variables from a CodeBuildStep,
and pipeline sources, and use them in the environment variables of
a CodeBuildStep or ShellStep.

Closes #17189, closes #18893, closes #15943, closes #16407.
@mergify mergify bot closed this as completed in #19024 Feb 23, 2022
mergify bot pushed a commit that referenced this issue Feb 23, 2022
Make it possible to export environment variables from a CodeBuildStep,
and pipeline sources, and use them in the environment variables of
a CodeBuildStep or ShellStep.

Closes #17189, closes #18893, closes #15943, closes #16407.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants