-
Notifications
You must be signed in to change notification settings - Fork 146
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
Why not to expose commit hash from SCM as an environment variable? #166
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this PR!
This is a common request and it is great to get some traction on it.
Unfortunately, the situation is a little more complex that it might seem at first.
Perhaps we could discuss a bit and I can help you figure what something that will work overall.
Thanks!
SCMHead head = branch.getHead(); | ||
// Note: not using Branch.name, since in the future that could be something different | ||
// than SCMHead.name, which is what we really want here. | ||
envs.put("BRANCH_NAME", head.getName()); | ||
if (rev != null) { | ||
envs.put("CHANGE_REVISION", rev.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that rev.toString()
is the right thing here, as it is intended to be
"human-readable". It may work in some of implementations but it, I'm not sure.
It looks like SCMRevision
doesn't have a method for what you're trying to do. There probably needs to be a getId()
method added to that in order for this to work reliably. Note, we'll also need to handle ChangeRequestSCMRevision differently since it has several possible revisions that users would be interested in.
It might be better if each SCM source implemented their own environment contributor.
Hi @bitwiseman , thanks for taking a look at this! |
The return value of this step should be a map containing the information you need. |
(Though beware GitHub PR merge builds.) |
I've started to use GitHub Branch Source plugin for my project. While developing my pipeline I was trying to set PR commit status for which I commit hash was needed. I was wondering if there any way to get it without
checkout
step. It didn't look too impossible - in Multibranch Pipelines and Organization Folders Jenkins "knows" from which commit has Jenkinsfile was taken. I've written the this https://gist.github.com/ababushk//930980d79ab09c74da34be459563f760 and added it to my Global Library. But it looks so "hacky" that I've started to search for a place where other environment variables likeCHANGE_ID
andBRANCH_NAME
are created. I've foundBranchNameContributor
class to which I've added variable that I desire so much.I'm completely new in Jenkins plugin development and Java in general, but I'm wondering why such simple thing as commit hash is not available by default.