且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Jenkins Git环境变量未在管道中设置

更新时间:2022-03-23 10:19:05

每页:

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

特定于SCM的变量(例如GIT_COMMIT)不会自动 定义为环境变量;而是可以使用返回值 结帐步骤.

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.

我相信这应该在Jenkins 2.60中解决:

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

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

请参阅JENKINS-45198的项目

See the item for JENKINS-45198

您可以通过在外壳中运行适当的git命令并将其分配给变量来解决:

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 )

在声明性管道中,您必须将其包装在script {}块中,并且可能在管道之外声明变量以获取适当的作用域.

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.