简体   繁体   English

GitVersion在Jenkins Multibranch Pipeline工作中

[英]GitVersion in a Jenkins Multibranch Pipeline job

We use Jenkins CI and have recently been experimenting with GitVersion for automatically generating SemVer version numbers. 我们使用Jenkins CI并且最近一直在尝试使用GitVersion来自动生成SemVer版本号。 However, when combining GitVersion with Multibranch Pipeline jobs (which automatically build branches and PRs for a given Git repository), we've run into GitVersion's limitation of only one remote (as enforced by its NormalizeGitDirectory function). 但是,当将GitVersion与Multibranch Pipeline作业(自动为给定的Git存储库自动构建分支和PR)组合时,我们只遇到GitVersion对一个远程的限制(由其NormalizeGitDirectory函数强制执行)。 The specific error we encounter is: 我们遇到的具体错误是:

System.ComponentModel.WarningException: 2 remote(s) have been detected. System.ComponentModel.WarningException:已检测到2个遥控器。 When being run on a build server, the Git repository is expected to bear one (and no more than one) remote. 当在构建服务器上运行时,Git存储库应该承载一个(并且不超过一个)远程。

The only solution we've found (as blogged here ) is to manually remove the "origin1" remote after the SCM checkout, prior to any build steps that would invoke GitVersion, like so: 我们已经找到了唯一的解决方案(如博客这里 )是手动删除“origin1”单片机结账后,遥控器,前,将调用GitVersion,像这样任何构建步骤:

bat 'git remote remove origin1'

This works but feels very much like a hack, and would likely not work with any fork-sourced PRs. 这有效,但感觉非常像黑客,并且可能不适用于任何来自源代码的PR。

Is there a better solution out there? 那里有更好的解决方案吗?

It seems that with pull request two remotes are required to track the build result for both (at least I was not getting back results on PR when upstream remote was removed) 似乎有拉动请求需要两个遥控器来跟踪两者的构建结果(至少我没有在上游远程被移除时取回PR的结果)

Using current 4.0.13 beta (and .12 beta) I tried to solve it by pulling directly, but there is a bug that affects calculation of current version when used directly ( https://github.com/GitTools/GitVersion/issues/1390 ) 使用当前4.0.13测试版(和.12测试版)我尝试通过直接拉动解决它,但有一个错误影响当前版本直接使用时的计算( https://github.com/GitTools/GitVersion/issues/ 1390

My current workaround is to remove upstream remote before: 我目前的解决方法是删除上游远程之前:

def remotes = bat(script: "@call git remote show", returnStdout: true).trim().readLines()
def hasUpstream = remotes.any { it == "upstream" }
def upstreamURL
if (hasUpstream) {
    echo "Remote 'upstream' detected -- ${env.BRANCH_NAME} is pull request, removing remote for further processing"
    upstreamURL = bat(script: "@call git remote get-url upstream", returnStdout: true).trim()
    bat "git remote remove upstream"
}

then execute: 然后执行:

def command = "@call ${BuildInfo.GitVersion.Run} /updateassemblyinfo /ensureassemblyinfo /nofetch /verbosity debug"
def output = bat(script: command, returnStdout: true).trim()

and add it back after: 并在以下后添加:

if (hasUpstream) {
    echo "Restoring 'upstream' remote using url: ${upstreamURL}"
    bat "git remote add -t master --tags upstream ${upstreamURL}"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM