GIT_COMMIT, GIT_URL, and other info is not returned in scm object or environment variables
red8888 opened this issue · 3 comments
Jenkins and plugins versions report
Environment
Paste the output here
What Operating System are you using (both controller, and any agents involved in the problem)?
linux
Reproduction steps
- Build a pipeline with the bitbucket plugin
Expected Results
I'm having trouble finding this in documentation anywhere, but from what I have seen I should be getting environment variables like GIT_COMMIT and GIT_URL populated OR that info should be available in the scm object.
Actual Results
Scm object does not include git commit and I don't have any env vars that have this info.
Anything else?
I just want to confirm if this is expected behavior. I don't want to have to shell out to git to get the commit id, url, commit message, commit user, etc.
- Build a pipeline with the bitbucket plugin
Do you mean the Bitbucket plugin or the Bitbucket Branch Source plugin?
When using the Bitbucket Branch Source plugin, env.GIT_COMMIT and env.GIT_URL is available in a declarative pipeline. I believe this actually set outside of the plugin. However, it seems it's not available in a scripted pipeline or I'm doing some silly error in the pipeline.
hudson.plugins.git.GitSCM.checkout sets some environment variables:
- GIT_COMMIT: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1332
- GIT_BRANCH: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1337
- GIT_LOCAL_BRANCH: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1346
hudson.plugins.git.GitSCM.buildEnvironment sets some environment variables:
- GIT_BRANCH: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1524
- GIT_LOCAL_BRANCH: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1535
- GIT_CHECKOUT_DIR: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1543
- GIT_PREVIOUS_COMMIT: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1548
- GIT_PREVIOUS_SUCCESSFUL_COMMIT: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1553
- GIT_COMMIT: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1559
- GIT_URL: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1575
- GIT_URL_number: https://github.com/jenkinsci/git-plugin/blob/git-4.11.4/src/main/java/hudson/plugins/git/GitSCM.java#L1580
I'm not sure in which situations GitSCM.buildEnvironment is called. It's conceivable that a scripted pipeline that runs a checkout
step might get GIT_COMMIT from GitSCM.checkout but not GIT_URL.