How to get bitbucket pull request id in CI?

  • Bitbucke Cloud
  • CI system used - Codebuild


I am wondering if I can get some guidance for finding the sonar.pullrequest.key automatically when a codebuild job is triggered by pull request?

Here is some context:
I am aware that if I use bitbucket cloud, most environment variables are populated automatically.
However, what if I want to use “other CI” option and I will have to construct the property file or add parameter using -D.

For example, in this article,

I wonder how the author is getting the context.env.CHANGE_ID variable? I assume it is from the pluging he is using. In my case, I will be using aws codebuild and I am wondering how I can get the bitbucket pull request id for -Dsonar.pullrequest.key?


Hi @void and welcome to the community !

How is triggered you Pull Request build in AWS ? Is this automatic ?


Yes. I plan to use the trigger on PR.
After I posted this question, it seems like pr/pull-request-number .is what I need?

Sounds like it yes !

1 Like