Why not to expose commit hash from SCM as an environment variable?#166
Why not to expose commit hash from SCM as an environment variable?#166ababushk wants to merge 1 commit intojenkinsci:masterfrom
Conversation
bitwiseman
left a comment
There was a problem hiding this comment.
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!
| // 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.
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
checkoutstep. 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_IDandBRANCH_NAMEare created. I've foundBranchNameContributorclass 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.