gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:12:01 26 4
gpt4 key购买 nike

我试图在 Jenkins 管道脚本中读取一些应该由 Git 插件设置的环境变量,但它们似乎没有设置,因为当我尝试在脚本中使用它的值是空字符串时,如果我使用 sh 'printenv'我可以看到它们没有设置。

可能我错过了一些东西,但我找不到什么。

任何的想法?

最佳答案

每页:

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.



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

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

查看 JENKINS-45198 的项目

您可以通过在 shell 中运行适当的 git 命令并将它们分配给变量来解决:
GIT_REVISION = sh( script: 'git rev-parse HEAD', returnStdout: true )

在声明式管道中,您必须将其包装在一个 script{} 块中,并可能在管道之外声明变量以获得适当的范围。

关于git - Jenkins Git 环境变量未在管道中设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46317774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com