Jenkins Workflow插件中的Git变量 [英] Git Variables in Jenkins Workflow plugin

查看:123
本文介绍了Jenkins Workflow插件中的Git变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从构建流中的git中进一步检出存储库时,我想访问git变量,例如GIT_COMMIT和GIT_BRANCH。目前我找不到可用的变量来访问这两个参数。

I'd like to access git variables such as GIT_COMMIT and GIT_BRANCH when I have checked out a repository from git further down in the build stream. Currently I find no available variable to access these two parameters.

node {
    git git+ssh://git.com/myproject.git
    echo "$GIT_COMMIT - $BRANCH_NAME"
}

是否可以使用这些变量,以防万一,我会在哪里找到它们。我不介意它们是否可以通过一些常规变量或任何地方获得,只要我可以访问它们即可。

Is such variables available and in case, where would I find them. I don't mind if they are available through some groovy variables or wherever, just that I can access them.

也许我缺乏Groovy中的调试技巧,这很容易找到,但我无法用我有限的技能找到它。

Maybe I lack the debugging skills in Groovy and this is easy to find, but I just can't find it with my limited skills.

推荐答案

我现在很好的解决这个问题的方法是要使用多分支管道,并且知道Bitbucket和Github在Jenkins中有插件可以很好地建立一个组织并自动发现新项目。这本身就可以用env.GIT_BRANCH

I good way to fix this for now is to use the Multi-branch pipeline, and it might be good to know that Bitbucket and Github have plugins in Jenkins that sets up an organisation and autodiscovers new projects. This works natively then with env.GIT_BRANCH

对于提交ID,我会建议@mkobit上面写的是什么。

For commit ID I would suggest what @mkobit wrote above.

这篇关于Jenkins Workflow插件中的Git变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆