We use Jenkins CI and have recently been experimenting with GitVersion for automatically generating SemVer version numbers. 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). The specific error we encounter is:
System.ComponentModel.WarningException: 2 remote(s) have been detected. When being run on a build server, the Git repository is expected to bear one (and no more than one) remote.
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:
bat 'git remote remove origin1'
This works but feels very much like a hack, and would likely not work with any fork-sourced PRs.
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)
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)
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}"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With