Handle case of tag not already existing in release repo correctly

This commit is contained in:
Dan Hawkins 2018-12-01 10:19:27 +00:00
commit 77c0c47b5c

View file

@ -3,9 +3,10 @@ unstablereason = ""
summaryfolder = "${WORKSPACE}/summary"
summaryfile = "${summaryfolder}/summary.txt"
summarystring = ""
releaserepofolder = "${WORKSPACE}/releaserepos"
tempfolder = "${WORKSPACE}/temp"
summarystring = ""
gitrevparseoutputfile = "${tempfolder}/gitrevparse.out"
metascript = autobuilder.getmetafolderscript()
@ -136,8 +137,9 @@ def ArrayList<String> maketaglist(String buildstamp, String otherreleasetags) {
def boolean releasegittag(String postcommitshacode, String tag) {
def boolean tagadded = false
// Check if tag exists already
def existingshacode = sh(script: "git rev-parse ${tag}", returnStdout: true).trim()
if (existingshacode?.trim()) { // If tag/sha code does exist
def int gitrevparsestatus = sh(script: "git rev-parse \"${tag}\" > \"${gitrevparseoutputfile}\"", returnStatus: true).trim()
if (gitrevparsestatus == 0) { // Tag exists
def existingshacode = readFile(file: gitrevparseoutputfile).trim()
if (existingshacode != postcommitshacode) { // If the existing tag is not associated with HEAD
// This is a problem - The tag is already at another position in git repo
setunstable("The tag ${tag} has been used at another commit other than HEAD - You must decide what to do with it - Not good practice to delete it or move it")
@ -147,9 +149,9 @@ def boolean releasegittag(String postcommitshacode, String tag) {
summaryappend("(${tag} - Already added)")
}
}
else { // If sha code does not exist already
else { // If tag does not exist already
// Tag
sh("git tag ${tag}")
sh("git tag \"${tag}\"")
summaryappend("(${tag})")
tagadded = true
}
@ -243,4 +245,4 @@ def releasehierarchy(buildmeta, String maxdepth, String otherreleasetags, String
return [summarystring, markunstable, unstablereason]
}
return this;
return this;