diff --git a/Jenkinsfile b/Jenkinsfile index 6f399a8..f5de784 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -62,16 +62,20 @@ env: [ RELEASE: false, DRYRUN: false, - VERSION: '0.0.1', BUILD_DIR: 'target', + GIT_CRED: 'bot-ci-dgm', DEPLOY_USER: 'root', - DEPLOY_HOST_STST: 'bxtsvctwas002.boxtel', + DEPLOY_HOST_STST: 'bxtsvctwas001.boxtel', + DEPLOY_HOST_ACC1: 'alasvctwas001.infra.qiy.nl', + DEPLOY_HOST_ACC2: 'alasvctwas002.infra.qiy.nl', + DEPLOY_HOST_PRD1: 'alpsvctwas001.infra.qiy.nl', + DEPLOY_HOST_PRD2: 'alpsvctwas002.infra.qiy.nl', DEPLOY_DIR: '/var/www/html/public/dummy-jenkins-pl', - DEPLOY_CRED: 'bot-ci-dgm', + DEPLOY_CRED: 'bot-ci-dgm-rsa', ], inLabels: [ 'ubuntu-16', 'centos-7' ], onLabels: [ default: 'master', docker: 'docker', mac: 'mac', android: 'android', ], - noPoll: '(.+_.+|release)', + noPoll: '(.+_.+)', ) lazyStage { @@ -117,9 +121,10 @@ [ run: { echo "Building packages"; - sh "mkdir -p ${env.BUILD_DIR} && echo 'testpkg' > ${env.BUILD_DIR}/\${LAZY_LABEL}.pkg" + def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + sh "mkdir -p ${env.BUILD_DIR} && echo 'testpkg-${currentVersione}' > ${env.BUILD_DIR}/\${LAZY_LABEL}.pkg" }, - in: [ 'ubuntu-16', 'centos-7', ], + in: '*', on: 'docker', post: { echo "Archiving packages" @@ -136,19 +141,31 @@ // 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 be use for the next 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('bot-ci-dgm-rsa', { + 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: impelement/import a generic helper for semantic versionning - def nextVersion = 'new' + 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) } - // Merge master into release branch + // Merge changes from working branch into release branch gitMerge(workingBranch, releaseBranch) // Bump version and tag the release branch before deploying sh("git checkout ${releaseBranch}") @@ -158,44 +175,82 @@ 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: { - gitAuth('bot-ci-dgm-rsa', { - gitTag("${currentVersion}", remote) + 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) }, - in: [ 'ubuntu-16', 'centos-7', ], on: 'docker', + // Can not be done in parallel + //in: '*', on: 'docker', ] } lazyStage { - name = 'publish' - onlyif = ( env.LAZY_BRANCH == 'master' || lazyConfig.env.RELEASE ) - input = 'Publish?' + name = 'systemtest' + onlyif = ( env.LAZY_BRANCH == releaseBranch ) + input = 'Deploy on systemtest?' tasks = [ - [ - pre: { - echo "Unarchiving packages" - unarchive(mapping:["${env.BUILD_DIR}/" : '.']) - sh("ls -lA target/packages") - }, - run: { - echo "Creating repo with packages" - }, - in: [ 'ubuntu-16', 'centos-7', ], - on: 'docker', - post: { - echo "Publishing package repos" - sshagent(credentials: [env.DEPLOY_CRED]) { - sshDeploy(env.BUILD_DIR, "${env.DEPLOY_USER}@${env.DEPLOY_HOST_STST}", env.DEPLOY_DIR) - } - }, - ], + pre: { + unarchive(mapping:["${env.BUILD_DIR}/" : '.']) + }, + run: { + echo "Creating repo with packages" + }, + in: '*', + on: 'docker', + post: { + echo "Publishing package repos" + sshagent(credentials: [env.DEPLOY_CRED]) { + sshDeploy(env.BUILD_DIR, "${env.DEPLOY_USER}@${env.DEPLOY_HOST_STST}", env.DEPLOY_DIR, 'rsync') + } + archiveArtifacts(artifacts: "${env.BUILD_DIR}/**", allowEmptyArchive: false) + }, ] } +lazyStage { + name = 'acceptance' + onlyif = ( lazyConfig['branch'] == releaseBranch ) + input = 'Deploy to acceptance?' + tasks = [ + pre: { + unarchive(mapping:["${env.BUILD_DIR}/" : '.']) + }, + run: { + sshagent(credentials: [env.DEPLOY_CRED]) { + sshDeploy(env.BUILD_DIR, "${env.DEPLOY_USER}@${env.DEPLOY_HOST_ACC1}", env.DEPLOY_DIR, 'rsync') + sshDeploy(env.BUILD_DIR, "${env.DEPLOY_USER}@${env.DEPLOY_HOST_ACC2}", env.DEPLOY_DIR, 'rsync') + } + }, + in: '*', + on: 'docker', + ] +} + +lazyStage { + name = 'production' + onlyif = ( lazyConfig['branch'] == releaseBranch ) + input = 'Deploy to production?' + tasks = [ + pre: { + unarchive(mapping:["${env.BUILD_DIR}/" : '.']) + }, + run: { + sshagent(credentials: [env.DEPLOY_CRED]) { + sshDeploy(env.BUILD_DIR, "${env.DEPLOY_USER}@${env.DEPLOY_HOST_PRD1}", env.DEPLOY_DIR, 'rsync') + sshDeploy(env.BUILD_DIR, "${env.DEPLOY_USER}@${env.DEPLOY_HOST_PRD2}", env.DEPLOY_DIR, 'rsync') + } + }, + in: '*', + on: 'docker', + ] +}