Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@aws-cdk/pipelines] - Can't get the Commit SHA

See original GitHub issue

When using GitHubSourceAction we should be able to get the “sha” of the commit that triggered the action. The TypeScript shows that it should be available under variables.commitId.

However, in my pipeline, it’s just giving me a template variable (or something like that): #{Source_GitHub_NS.CommitId}

Reproduction Steps

The code looks like this:

const sourceAction = new cpa.GitHubSourceAction({
      actionName: "GitHub",
      output: sourceArtifact,
      oauthToken: cdk.SecretValue.secretsManager("github-repo-token"),
      owner: "github-username",
      repo: "the-repo",
      branch: "dev",

    const sha = sourceAction.variables.commitId // returns #{Source_GitHub_NS.CommitId}

How can we get the actual SHA in this scenario?

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

skinny85commented, Nov 2, 2020

Hey @arpowers ,

thanks for opening the issue. The commit is only available during Pipeline execution, as it changes each time you push something to your repository. That’s why it’s available as this #{Source_GitHub_NS.CommitId} expression. You can pass it to a different thing in your pipeline - for example, the environment variables of your CodeBuild Project:

new CodeBuildAction({
  // ...
  environmentVariables: {
    COMMIT_ID: { value: sourceAction.variables.commitId },

And then read the COMMIT_ID environment variable when executing the build.

Hope this clears this up!

Thanks, Adam

github-actions[bot]commented, Jan 25, 2021


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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get source repo commit hash in AWS code build step
Found a solution that works for me: PIPELINE_EXECUTION_ID=$(aws codepipeline get-pipeline-state --region ${AWS_REGION} --name my-pipeline ...
Read more >
aws-cdk/aws-codepipeline-actions module
When you want to have multiple inputs and/or outputs for a Project used in a Pipeline, instead of using the secondarySources and secondaryArtifacts...
Read more >
aws-cdk/pipelines module - AWS Documentation -
The reason is that the pipeline will start deploying and self-mutating right away based on the sources in the repository, so the sources...
Read more >
Environment variables in build environments - AWS CodeBuild
If CodePipeline is not able to resolve the source revision, such as when the source is an Amazon S3 bucket that does not...
Read more >
Building, bundling, and deploying applications with the AWS ...
The post CDK Pipelines: Continuous delivery for AWS CDK applications ... Because we don't commit the Go executable to our source repository, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found