diff --git a/Jenkinsfile b/Jenkinsfile index 94fc241..c016364 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -80,11 +80,11 @@ lazyStage { name = 'validate' - onlyif = ( lazyConfig['branch'] != releaseBranch) + onlyif = ( lazyConfig['branch'] != releaseBranch) // Skip when releasing tasks = [ [ pre: { - def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + def currentVersion = gitLastTag() currentBuild.displayName = "#${env.BUILD_NUMBER} ${currentVersion}" }, run: { @@ -100,7 +100,7 @@ lazyStage { name = 'test' - onlyif = ( lazyConfig['branch'] != releaseBranch) + onlyif = ( lazyConfig['branch'] != releaseBranch) // Skip when releasing tasks = [ [ run: { echo "This is my fith task" }, ], [ @@ -121,18 +121,26 @@ // [ run: { echo "Building packages"; echo "Archive packages"; }, on: 'windows', ] // [ run: { echo "Building packages"; echo "Archive packages"; }, on: 'mac', ] [ - run: { - echo "Building packages"; - def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + 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') + } else { + // Write version from tag to generate the site + writedFile(encoding: 'UTF-8', file: 'version.txt', text: currentVersion) + } currentBuild.displayName = "#${env.BUILD_NUMBER} ${currentVersion}" + }, + run: { sh "mkdir -p ${env.BUILD_DIR} && echo 'testpkg-${currentVersion}' > ${env.BUILD_DIR}/\${LAZY_LABEL}.pkg" }, + post: { + archiveArtifacts(artifacts: "${env.BUILD_DIR}/**", allowEmptyArchive: false) + }, in: '*', on: 'docker', - post: { - echo "Archiving packages" - archiveArtifacts(artifacts: "${env.BUILD_DIR}/**", allowEmptyArchive: false) - }, ], ] } @@ -151,11 +159,11 @@ )] ] tasks = [ - pre: { + run: { gitAuth(env.GIT_CRED, { // Switch to release branch to bump version sh("git checkout ${releaseBranch}") - def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + def currentVersion = readFile(encoding: 'UTF8', file: 'version.txt') // Define next version based on optional input def nextVersion = null @@ -169,34 +177,22 @@ nextVersion = bumpVersion('build', currentVersion) } // Merge changes from working branch into release branch - gitMerge(workingBranch, releaseBranch) + gitMerge(workingBranch) // Bump version and tag the release branch before deploying - sh("git checkout ${releaseBranch}") - writeFile(encoding: 'UTF-8', text: nextVersion, file: 'version.txt') + writeFile(encoding: 'UTF-8', file: 'version.txt', text: nextVersion) gitCommit("Update version to ${nextVersion}", 'version.txt') - }) - unarchive(mapping:["${env.BUILD_DIR}/" : '.']) - }, - run: { - 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, { // 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) }, // Can not be done in parallel - //in: '*', on: 'docker', ] } +// Deliver the site on each environment lazyStage { name = 'systemtest' onlyif = ( env.LAZY_BRANCH == releaseBranch )