fix(cpkg): reuse latest version number
This commit is contained in:
parent
77a7c46d3f
commit
1ddb5691ca
@ -1,8 +1,8 @@
|
||||
import java.util.regex.Matcher
|
||||
|
||||
// Basic port of https://forge.cadoles.com/Cadoles/cpkg
|
||||
def call(Map params = [:]) {
|
||||
|
||||
def currentRef = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
||||
def baseRef = params.baseRef ? params.baseRef : currentRef
|
||||
def distRepo = params.distRepo ? params.distRepo : 'dev'
|
||||
def dist = params.dist ? params.dist : 'eole'
|
||||
def distVersion = params.distVersion ? params.distVersion : '2.7.0'
|
||||
@ -12,7 +12,7 @@ def call(Map params = [:]) {
|
||||
def gitEmail = params.gitEmail ? params.gitEmail : 'jenkins@cadoles.com'
|
||||
def gitUsername = params.gitUsername ? params.gitUsername : 'Jenkins'
|
||||
def skipCi = params.containsKey('skipCi') ? params.skipCi : false
|
||||
def skipPush = params.containsKey('skipPush') ? params.skipPush: true
|
||||
def skipPush = params.containsKey('skipPush') ? params.skipPush : true
|
||||
|
||||
// Define dist branch based on provided informations and base branch name
|
||||
def distBranch = "dist/${dist}/${distVersion}/${distBranchName}"
|
||||
@ -28,7 +28,7 @@ def call(Map params = [:]) {
|
||||
sh("git config --add remote.origin.fetch +refs/heads/${distBranch}:refs/remotes/origin/${distBranch}")
|
||||
|
||||
// Update branches
|
||||
sh("git fetch --all")
|
||||
sh('git fetch --all')
|
||||
|
||||
// Merge currentRef into distBranch and push
|
||||
sh("git checkout -b '${distBranch}' 'origin/${distBranch}'")
|
||||
@ -40,7 +40,7 @@ def call(Map params = [:]) {
|
||||
sh("git merge ${currentRef}")
|
||||
|
||||
if (!skipPush) {
|
||||
sh("git push")
|
||||
sh('git push')
|
||||
} else {
|
||||
println("Skipping push. Set skipPush param to 'true' to enable remote repository update.")
|
||||
}
|
||||
@ -61,15 +61,22 @@ def call(Map params = [:]) {
|
||||
|
||||
println("Last version number is '${lastVersionNumber}'")
|
||||
|
||||
def versionNumber = sh(
|
||||
script: "git describe --always ${currentRef}",
|
||||
returnStdout: true,
|
||||
).split('/').last().trim()
|
||||
String versionRoot = extractVersionRoot(lastVersionNumber)
|
||||
String versionNumber = ''
|
||||
|
||||
def isCommitRef = !versionNumber.matches(/^[0-9]+\.[0-9]+\.[0-9]+.*$/)
|
||||
if (versionRoot) {
|
||||
versionNumber = versionRoot
|
||||
} else {
|
||||
versionNumber = sh(
|
||||
script: "git describe --always ${currentRef}",
|
||||
returnStdout: true,
|
||||
).split('/').last().trim()
|
||||
|
||||
if (isCommitRef) {
|
||||
versionNumber = "0.0.0-${versionNumber}"
|
||||
Boolean isCommitRef = !versionNumber.matches(/^[0-9]+\.[0-9]+\.[0-9]+.*$/)
|
||||
|
||||
if (isCommitRef) {
|
||||
versionNumber = "0.0.0-${versionNumber}"
|
||||
}
|
||||
}
|
||||
|
||||
versionNumber = "${versionNumber}-b${env.BUILD_NUMBER}"
|
||||
@ -82,7 +89,7 @@ def call(Map params = [:]) {
|
||||
|
||||
result['newTag'] = tag
|
||||
|
||||
def tagComment="Build ${versionNumber} ${distRepo} package for ${dist}-${distVersion}."
|
||||
def tagComment = "Build ${versionNumber} ${distRepo} package for ${dist}-${distVersion}."
|
||||
if (skipCi) {
|
||||
tagComment += ' [ci skip]'
|
||||
}
|
||||
@ -91,7 +98,7 @@ def call(Map params = [:]) {
|
||||
|
||||
// Push tag
|
||||
if (!skipPush) {
|
||||
sh("git push --tags -f")
|
||||
sh('git push --tags -f')
|
||||
} else {
|
||||
println("Skipping push. Set skipPush param to 'true' to enable remote repository update.")
|
||||
}
|
||||
@ -117,4 +124,15 @@ def call(Map params = [:]) {
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
String extractVersionRoot(String fullVersion) {
|
||||
Matcher fullVersionMatcher = fullVersion =~ /^([0-9]+\.[0-9]+\.[0-9]+).*$/
|
||||
|
||||
if (!fullVersionMatcher.matches()) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return fullVersionMatcher.group(1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user