diff --git a/Jenkinsfile b/Jenkinsfile index 69ce7e8..09d8d78 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -137,17 +137,27 @@ // Ask version if release flag and set and we are in the branch to fork release from input = [ message: 'Version string', - parameters: [string(defaultValue: '', description: 'Version string to release', name: 'VERSION')] + parameters: [string( + defaultValue: '', + description: "Version to be release: 'build', 'micro', 'minor', 'major' or a specific string (i.e.: 1.2.3-4)", + name: 'VERSION' + )] ] tasks = [ pre: { - def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') gitAuth(env.GIT_CRED, { + // Switch to release branch to bump version + sh("git checkout ${releaseBranch}") + def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + // Define next version based on optional input - // TODO: implement/import a generic helper for semantic versionning def nextVersion = null if (env.lazyInput) { - nextVersion = env.lazyInput + if (env.lazyInput ==~ /[a-z]+/) { + nextVersion = bumpVersion(env.lazyInput, currentVersion) + } else { + nextVersion = env.lazyInput + } } else { nextVersion = bumpVersion('build', currentVersion) } @@ -158,24 +168,25 @@ writeFile(encoding: 'UTF-8', text: nextVersion, file: 'version.txt') gitCommit("Update version to ${nextVersion}", 'version.txt') }) - currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') - currentBuild.displayName = "#${env.BUILD_NUMBER} ${currentVersion}" unarchive(mapping:["${env.BUILD_DIR}/" : '.']) }, run: { - def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') - // Rebuild the site with the new version - echo("Rebuild for version ${currentVersion}") + echo("Rebuild for new version ...") }, post: { def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + currentBuild.displayName = "#${env.BUILD_NUMBER} ${currentVersion}" gitAuth(env.GIT_CRED, { - gitTag("${currentVersion}", remote) + // Uncomment the following to merge version bump back into the working branch + //gitMerge(releaseBranch, workingBranch) + //gitPush(remote, workingBranch) gitPush(remote, releaseBranch) + gitTag("${currentVersion}", remote) }) archiveArtifacts(artifacts: "${env.BUILD_DIR}/**", allowEmptyArchive: false) }, - in: '*', on: 'docker', + // Can not be done in parallel + //in: '*', on: 'docker', ] }