# Jenkins environment variables for bitbucket Pull request are showing null values, why?

**URL:** <https://community.jenkins.io/t/jenkins-environment-variables-for-bitbucket-pull-request-are-showing-null-values-why/7752>\
**Category:** Using Jenkins\
**Tags:** question\
**Created:** [June 1, 2023, 10:46am UTC](https://community.jenkins.io/t/jenkins-environment-variables-for-bitbucket-pull-request-are-showing-null-values-why/7752 "2023-06-01T10:46:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![swsing](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@swsing](https://community.jenkins.io/u/swsing)\
**Post date:** [June 1, 2023, 10:46am UTC](https://community.jenkins.io/t/jenkins-environment-variables-for-bitbucket-pull-request-are-showing-null-values-why/7752/1 "2023-06-01T10:46:22Z")

</div>

We have a test-application with webhook(bitbucket scm source hook) configured in repository settings.  
We want to check if bitbucket Pull Request is open or not from a branch to master branch based on bitbucket environment variable values in Jenkins.  
But we get the values of bitbucket environment variables as null in the jenkins console logs, even though the PR is open.

There is a Pull Request section in Jenkins Job that shows PR with it’s ID, there I am able to see the PR-14(head) and PR-14(merge), where 14 is the PR ID. But then why is the value of ${env.BITBUCKET\_PULL\_REQUEST\_ID} coming out to be null?

Can some one please help me with this?

```auto
Jenkinsfile build stage code :-
/* Development zone */
				stage('Build') {
						steps{
								echo "Value of env.BITBUCKET_PULL_REQUEST_ID is ${env.BITBUCKET_PULL_REQUEST_ID}"
								echo "Value of env.BITBUCKET_SOURCE_BRANCH is ${env.BITBUCKET_SOURCE_BRANCH}"
								echo "Value of env.BITBUCKET_TARGET_BRANCH is ${env.BITBUCKET_TARGET_BRANCH}"

								echo "Value of env.BRANCH_NAME is ${env.BRANCH_NAME}"
								echo "Value of env.CHANGE_ID is ${env.CHANGE_ID}"
						}
				}

```

---

<div class="post-metadata">

**Author:** ![wiiNinja](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/wiininja/32/5893_2.png) [@wiiNinja](https://community.jenkins.io/u/wiiNinja)\
**Post date:** [November 6, 2023, 11:37am UTC](https://community.jenkins.io/t/jenkins-environment-variables-for-bitbucket-pull-request-are-showing-null-values-why/7752/2 "2023-11-06T11:37:10Z")

</div>

We’re using BitBucket Server in our organization, and I’m also seeing the same thing, and would also appreciate any help figuring this out. Also any suggestions on alternate methods of figuring out if a branch has an open pull request would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [November 9, 2023, 2:13pm UTC](https://community.jenkins.io/t/jenkins-environment-variables-for-bitbucket-pull-request-are-showing-null-values-why/7752/3 "2023-11-09T14:13:18Z")

</div>

I think the variables `BITBUCKET_PULL_REQUEST_ID`, `BITBUCKET_SOURCE_BRANCH`, and `BITBUCKET_TARGET_BRANCH` are not standard environment variables provided by Jenkins or the Bitbucket Branch Source Plugin. 🤷

Instead, you might want to use the following environment variables:

- [`BRANCH_NAME`: This is set to the repository branch name](https://stackoverflow.com/questions/60711551/jenkins-pipeline-determine-if-a-branch-is-for-bitbucket-pull-request).
- `CHANGE_ID`: This is set when a multibranch pipeline build is triggered from a pull request.

Please note that these variables are only available when you run a multibranch pipeline build: [In Jenkins pipeline some environment variables are having null value - Stack Overflow](https://stackoverflow.com/questions/46232900/in-jenkins-pipeline-some-environment-variables-are-having-null-value).

---

<div class="post-metadata">

**Author:** ![kon](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/kon/32/1197_2.png) [@kon](https://community.jenkins.io/u/kon)\
**Post date:** [November 10, 2023, 9:38pm UTC](https://community.jenkins.io/t/jenkins-environment-variables-for-bitbucket-pull-request-are-showing-null-values-why/7752/4 "2023-11-10T21:38:47Z")

</div>

BITBUCKET\_PULL\_REQUEST\_ID etc. environment variables are documented for Bitbucket Push and Pull Request Plugin: [Bitbucket Push and Pull Request](https://plugins.jenkins.io/bitbucket-push-and-pull-request/#plugin-content-environment-variables)

I don’t have enough experience with that to recommend whether to use it or not.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [November 10, 2023, 9:50pm UTC](https://community.jenkins.io/t/jenkins-environment-variables-for-bitbucket-pull-request-are-showing-null-values-why/7752/5 "2023-11-10T21:50:19Z")

</div>

My bad, thanks for correcting. 👍
