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

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

问题描述

当我在构建流中从 git 检出存储库时,我想访问诸如 GIT_COMMITGIT_BRANCH 之类的 git 变量.目前我发现没有可用的变量来访问这两个参数.

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天全站免登陆