jenkinsci / jenkinsci/branch-api-plugin

[JENKINS-58313] Expose pullrequest source commit hash to pipeline env variables

Open
#728 1 comment 0 reactions 0 assignees View on GitHub
component:branch-api-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
39
Forks
154
PR merge metrics
No merged PRs in 30d

Description

Some operations on pullrequests (like reporting build statuses or creating reports) require to pass the hash of the pullrequest branch head, as known by the remote system.

When using the branch plugin, Jenkins may create a merge commit between the PR source and target branch. It makes it difficult for a pipeline script to retrieve the original source commit hash.

My suggestion is to add a new environment variable, similar to CHANGE_BRANCH, that would expose this source commit. We could name this variable CHANGE_BRANCH_COMMIT_ID, to make it consistent with existing CHANGE_BRANCH and COMMIT_ID.

See original discussion:

https://groups.google.com/d/topic/jenkinsci-dev/-ojqklsaKbw/discussion

Example of operations requiring the PR head commit hash:


---
Originally reported by henryju, imported from: Expose pullrequest source commit hash to pipeline env variables


  • assignee: henryju
  • status: Open
  • priority: Minor
  • component(s): branch-api-plugin
  • resolution: Unresolved
  • votes: 4
  • watchers: 3
  • imported: 20251211-141027

Raw content of original issue

Some operations on pullrequests (like reporting build statuses or creating reports) require to pass the hash of the pullrequest branch head, as known by the remote system.
When using the branch plugin, Jenkins may create a merge commit between the PR source and target branch. It makes it difficult for a pipeline script to retrieve the original source commit hash.

My suggestion is to add a new environment variable, similar to CHANGE_BRANCH, that would expose this source commit. We could name this variable CHANGE_BRANCH_COMMIT_ID, to make it consistent with existing CHANGE_BRANCH and COMMIT_ID.

See original discussion:
https://groups.google.com/d/topic/jenkinsci-dev/-ojqklsaKbw/discussion

Example of operations requiring the PR head commit hash:



  • environment: GitHub, Bitbucket

Contributor guide

Open the contributing guide

Research direction

The issue names no source file or test; start by locating the branch-api-plugin code and tests that expose existing CHANGE_BRANCH and COMMIT_ID pipeline environment variables. Trace how pull request source metadata is provided, then add the proposed source commit variable and verify it for pull request builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, java
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.