Génération automatique de version avec incrément piloté par git
This commit is contained in:
parent
45ff14ce10
commit
bcf34404a2
|
@ -44,7 +44,7 @@ def call(Map params = [:]) {
|
||||||
} else {
|
} else {
|
||||||
println("Skipping push. Set skipPush param to 'true' to enable remote repository update.")
|
println("Skipping push. Set skipPush param to 'true' to enable remote repository update.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve last tag matching pattern pkg/${distRepo}/${dist}-${distVersion}/*
|
// Retrieve last tag matching pattern pkg/${distRepo}/${dist}-${distVersion}/*
|
||||||
def lastTag = sh(
|
def lastTag = sh(
|
||||||
script: "git tag -l 'pkg/${distRepo}/${dist}-${distVersion}/*' --sort=v:refname | tail -n 1",
|
script: "git tag -l 'pkg/${distRepo}/${dist}-${distVersion}/*' --sort=v:refname | tail -n 1",
|
||||||
|
@ -61,7 +61,16 @@ def call(Map params = [:]) {
|
||||||
|
|
||||||
println("Last version number is '${lastVersionNumber}'")
|
println("Last version number is '${lastVersionNumber}'")
|
||||||
|
|
||||||
def versionNumber = incrementVersionNumber(lastVersionNumber)
|
def versionNumber = sh(
|
||||||
|
script: "git describe --always ${currentRef}",
|
||||||
|
returnStdout: true,
|
||||||
|
).trim()
|
||||||
|
|
||||||
|
def isCommitRef = !versionNumber.matches(/^[0-9]+\.[0-9]+\.[0-9]+.*$/)
|
||||||
|
|
||||||
|
if (isCommitRef) {
|
||||||
|
versionNumber = "0.0.0-${versionNumber}"
|
||||||
|
}
|
||||||
|
|
||||||
println("New version number will be '${versionNumber}'")
|
println("New version number will be '${versionNumber}'")
|
||||||
result['newVersionNumber'] = versionNumber
|
result['newVersionNumber'] = versionNumber
|
||||||
|
@ -106,22 +115,4 @@ def call(Map params = [:]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
|
||||||
|
|
||||||
def incrementVersionNumber(String versionNumber) {
|
|
||||||
// Split versionNumber (typical pattern: <major>.<minor>.<patch>)
|
|
||||||
def versionNumberParts = versionNumber.split(/\./)
|
|
||||||
|
|
||||||
// Extract path number
|
|
||||||
def patchNumber = versionNumberParts.last()
|
|
||||||
|
|
||||||
// Split patch number (typical pattern: <patch>-<build>)
|
|
||||||
def patchNumberParts = patchNumber.split('-')
|
|
||||||
|
|
||||||
// If version number matches pattern <major>.<minor>.<patch>-<build>
|
|
||||||
if (patchNumberParts.size() > 1) {
|
|
||||||
return versionNumberParts[0..-2].join('.') + '.' + patchNumberParts[0..-2].join('-') + '-' + (patchNumberParts.last().toInteger() + 1)
|
|
||||||
} else { // Else version number matches pattern <major>.<minor>.<patch>
|
|
||||||
return versionNumberParts[0..-2].join('.') + '.' + (patchNumber.toInteger() + 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue