Jenkins管道:检出显式git commit [英] Jenkins pipeline: checkout explicit git commit

查看:135
本文介绍了Jenkins管道:检出显式git commit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够说些类似的话:

I want to be able to say something like:

git branch: commitHash, credentialsId: credentialsId, url: url

用例:我正在并行构建和测试在不同平台上的运行,并希望确保每一个都获得相同的代码.它是C ++,我们可以在独立的平台上构建,也可以在它们之上构建.

The usecase: I'm doing parallel build and test runs on different platforms, and want to ensure each gets the same code. It is C++, and we build on separate platforms as well as building on them.

如果执行上述操作,它将失败-基础代码假定给定的分支实际上是一个分支,或者您得到类似以下内容的信息:

If I do the above, it fails - the underlying code assumes the given branch actually is a branch, or you get something like:

[Linux64 Build]  > git rev-parse origin/e4b6c976a0a986c348a211579f1e8fd32cf29567^{commit} # timeout=10
[Pipeline] [Linux64 Build] }
[Pipeline] [Linux64 Build] // dir
[Pipeline] [Linux64 Build] }
[Pipeline] [Linux64 Build] // node
[Pipeline] [Linux64 Build] }
[Linux64 Build] Failed in branch Linux64 Build

虽然没有实际的答案,但我之前看到过这个问题的变体,只是一些建议喜欢隐藏源代码,等等.这并不是我真正想要的.

I've seen variations on this question asked before, although no actual answers - just suggestions like to stash the source code instead, etc. Not really what I'm after.

文档显示应该有可能给出明确的提交哈希,可能使用分支代替,但是我无法弄清楚语法,也找不到任何示例.当我这样做时,我想得到了master分支-在我们的设置中,master无法正常工作.

The documentation suggests it ought to be possible to give explicit commit hashes, possibly using branches instead, but I can't work out the syntax and can't find any examples. When I do it, I get the master branch, I think - in our setup, master does not work.

到目前为止,我发现的唯一解决方案是检出分支,然后显式调用git进行提交:

So far, the only solution I've found has been to checkout the branch and then explicitly call git to get the commit:

                git branch: branch, credentialsId: credentialsId, url: url
                sh 'git checkout ' + commitHash

(其中branch是我最初在工作顶部获得哈希值的分支.它可以工作,但不是最简洁的.

(where branch is the branch I originally got the hash for at the top of the job. It works but is not the neatest.

有人有更好的方法吗?

推荐答案

使用 查看全文

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