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
|
// Basic port of https://forge.cadoles.com/Cadoles/cpkg
|
||||||
def call(Map params = [:]) {
|
def call(Map params = [:]) {
|
||||||
|
|
||||||
def currentRef = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
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 distRepo = params.distRepo ? params.distRepo : 'dev'
|
||||||
def dist = params.dist ? params.dist : 'eole'
|
def dist = params.dist ? params.dist : 'eole'
|
||||||
def distVersion = params.distVersion ? params.distVersion : '2.7.0'
|
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 gitEmail = params.gitEmail ? params.gitEmail : 'jenkins@cadoles.com'
|
||||||
def gitUsername = params.gitUsername ? params.gitUsername : 'Jenkins'
|
def gitUsername = params.gitUsername ? params.gitUsername : 'Jenkins'
|
||||||
def skipCi = params.containsKey('skipCi') ? params.skipCi : false
|
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
|
// Define dist branch based on provided informations and base branch name
|
||||||
def distBranch = "dist/${dist}/${distVersion}/${distBranchName}"
|
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}")
|
sh("git config --add remote.origin.fetch +refs/heads/${distBranch}:refs/remotes/origin/${distBranch}")
|
||||||
|
|
||||||
// Update branches
|
// Update branches
|
||||||
sh("git fetch --all")
|
sh('git fetch --all')
|
||||||
|
|
||||||
// Merge currentRef into distBranch and push
|
// Merge currentRef into distBranch and push
|
||||||
sh("git checkout -b '${distBranch}' 'origin/${distBranch}'")
|
sh("git checkout -b '${distBranch}' 'origin/${distBranch}'")
|
||||||
|
@ -40,7 +40,7 @@ def call(Map params = [:]) {
|
||||||
sh("git merge ${currentRef}")
|
sh("git merge ${currentRef}")
|
||||||
|
|
||||||
if (!skipPush) {
|
if (!skipPush) {
|
||||||
sh("git push")
|
sh('git push')
|
||||||
} 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.")
|
||||||
}
|
}
|
||||||
|
@ -61,15 +61,22 @@ def call(Map params = [:]) {
|
||||||
|
|
||||||
println("Last version number is '${lastVersionNumber}'")
|
println("Last version number is '${lastVersionNumber}'")
|
||||||
|
|
||||||
def versionNumber = sh(
|
String versionRoot = extractVersionRoot(lastVersionNumber)
|
||||||
script: "git describe --always ${currentRef}",
|
String versionNumber = ''
|
||||||
returnStdout: true,
|
|
||||||
).split('/').last().trim()
|
|
||||||
|
|
||||||
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) {
|
Boolean isCommitRef = !versionNumber.matches(/^[0-9]+\.[0-9]+\.[0-9]+.*$/)
|
||||||
versionNumber = "0.0.0-${versionNumber}"
|
|
||||||
|
if (isCommitRef) {
|
||||||
|
versionNumber = "0.0.0-${versionNumber}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
versionNumber = "${versionNumber}-b${env.BUILD_NUMBER}"
|
versionNumber = "${versionNumber}-b${env.BUILD_NUMBER}"
|
||||||
|
@ -82,7 +89,7 @@ def call(Map params = [:]) {
|
||||||
|
|
||||||
result['newTag'] = tag
|
result['newTag'] = tag
|
||||||
|
|
||||||
def tagComment="Build ${versionNumber} ${distRepo} package for ${dist}-${distVersion}."
|
def tagComment = "Build ${versionNumber} ${distRepo} package for ${dist}-${distVersion}."
|
||||||
if (skipCi) {
|
if (skipCi) {
|
||||||
tagComment += ' [ci skip]'
|
tagComment += ' [ci skip]'
|
||||||
}
|
}
|
||||||
|
@ -91,7 +98,7 @@ def call(Map params = [:]) {
|
||||||
|
|
||||||
// Push tag
|
// Push tag
|
||||||
if (!skipPush) {
|
if (!skipPush) {
|
||||||
sh("git push --tags -f")
|
sh('git push --tags -f')
|
||||||
} 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.")
|
||||||
}
|
}
|
||||||
|
@ -117,4 +124,15 @@ def call(Map params = [:]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
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