Jenkins Git Environment variables not set in Pipeline

做~自己de王妃 提交于 2019-12-07 23:49:22

问题


I am trying to read some environment variables in Jenkins pipeline script that should be set by Git plugin, but it seems they are not set, because when I tried to use in script its value is empty string and also if I use sh 'printenv' I can see that they are not set.

Probably I am missing something but I cannot find what.

Any idea?


回答1:


Per this page:

http://JenkinsURL/pipeline-syntax/globals:

SCM-specific variables such as GIT_COMMIT are not automatically defined as environment variables; rather you can use the return value of the checkout step.

This is supposed to be resolved in Jenkins 2.60, I believe:

https://plugins.jenkins.io/pipeline-model-definition

See the item for JENKINS-45198

You can workaround by running the appropriate git commands in a shell and assigning them to a variable:

GIT_REVISION = sh( script: 'git rev-parse HEAD', returnStdout: true )

In a Declarative pipeline, you will have to wrap this in a script{} block, and probably declare the variable outside of your pipeline to get the appropriate scope.



来源:https://stackoverflow.com/questions/46317774/jenkins-git-environment-variables-not-set-in-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!