diff --git a/Jenkinsfile b/Jenkinsfile index db73b2c..74d6e34 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,6 @@ lazyConfig( name: 'dummy-jenkins-pl', env: [ - RELEASE: false, DRYRUN: false, BUILD_DIR: 'target', GIT_CRED: 'bot-ci-dgm', @@ -75,7 +74,7 @@ ], inLabels: [ 'ubuntu-16', 'centos-7' ], onLabels: [ default: 'master', docker: 'docker', mac: 'mac', android: 'android', ], - noPoll: '(.+_.+)', + noPoll: '(releaseBranch|.+_.+)', ) lazyStage { @@ -115,6 +114,50 @@ ] } +// Release stage only only if criteria are met +lazyStage { + name = 'release' + onlyif = ( lazyConfig['branch'] == releaseBranch ) + // 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 to be release: 'build', 'micro', 'minor', 'major' or a specific string (i.e.: 1.2.3-4)", + name: 'VERSION' + )] + ] + tasks = [ + run: { + gitAuth(env.GIT_CRED, { + // Define next version based on optional input + def currentVersion = readFile(encoding: 'UTF8', file: 'version.txt') + def nextVersion = null + if (env.lazyInput) { + if (env.lazyInput ==~ /[a-z]+/) { + nextVersion = bumpVersion(env.lazyInput, currentVersion) + } else { + nextVersion = env.lazyInput + } + } else { + nextVersion = bumpVersion('build', currentVersion) + } + // Merge changes from working branch + gitMerge(workingBranch, releaseBranch) + // Bump version and tag before deploying + writeFile(encoding: 'UTF-8', file: 'version.txt', text: nextVersion) + gitCommit("Update version to ${nextVersion}", 'version.txt') + // Uncomment the following to merge version bump back into the working branch + //gitMerge(releaseBranch, workingBranch) + //gitPush(remote, workingBranch) + gitPush(remote, releaseBranch) + gitTag("${nextVersion}", remote) + }) + }, + // Can not be done in parallel + ] +} + lazyStage { name = 'package' tasks = [ @@ -123,12 +166,15 @@ [ pre: { // Read version from last git tag first - def currentVersion = gitLastTag() - if (lazyConfig['branch'] == releaseBranch) { - // Read version from code if releasing - currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + def currentVersion = null + gitAuth(env.GIT_CRED, { + currentVersion = gitLastTag() + }) + if (lazyConfig['branch'] == releaseBranch) { + // Checkout the last changes from the tag created in release stage + sh("git checkout tags/${currentVersion}") } else { - // Write version from tag to generate the site + // Write version from last tag to generate the site writeFile(encoding: 'UTF-8', file: 'version.txt', text: currentVersion) } currentBuild.displayName = "#${env.BUILD_NUMBER} ${currentVersion}" @@ -145,53 +191,6 @@ ] } -// Release stage only only if criteria are met -lazyStage { - name = 'release' - onlyif = ( lazyConfig['branch'] == workingBranch && lazyConfig.env.RELEASE ) - // 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 to be release: 'build', 'micro', 'minor', 'major' or a specific string (i.e.: 1.2.3-4)", - name: 'VERSION' - )] - ] - tasks = [ - run: { - gitAuth(env.GIT_CRED, { - // Switch to release branch to bump version - sh("git checkout ${releaseBranch}") - def currentVersion = readFile(encoding: 'UTF8', file: 'version.txt') - - // Define next version based on optional input - def nextVersion = null - if (env.lazyInput) { - if (env.lazyInput ==~ /[a-z]+/) { - nextVersion = bumpVersion(env.lazyInput, currentVersion) - } else { - nextVersion = env.lazyInput - } - } else { - nextVersion = bumpVersion('build', currentVersion) - } - // Merge changes from working branch into release branch - gitMerge(workingBranch) - // Bump version and tag the release branch before deploying - writeFile(encoding: 'UTF-8', file: 'version.txt', text: nextVersion) - gitCommit("Update version to ${nextVersion}", 'version.txt') - // Uncomment the following to merge version bump back into the working branch - //gitMerge(releaseBranch, workingBranch) - //gitPush(remote, workingBranch) - gitPush(remote, releaseBranch) - gitTag("${nextVersion}", remote) - }) - }, - // Can not be done in parallel - ] -} - // Deliver the site on each environment lazyStage { name = 'systemtest'