diff --git a/Jenkinsfile b/Jenkinsfile index 6149685..6f399a8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,34 +21,34 @@ // Load Jenkins shared libraries common to all projects def libLazy = [ - remote: 'https://code.in.digital-me.nl/git/DEVops/JenkinsLibLazy.git', - branch: env.BRANCH_NAME, - credentialsId: null, + remote: 'https://code.in.digital-me.nl/git/DEVops/JenkinsLibLazy.git', + branch: env.BRANCH_NAME, + credentialsId: null, ] library( - identifier: "libLazy@${libLazy.branch}", - retriever: modernSCM([ - $class: 'GitSCMSource', - remote: libLazy.remote, - credentialsId: libLazy.credentialsId - ]) + identifier: "libLazy@${libLazy.branch}", + retriever: modernSCM([ + $class: 'GitSCMSource', + remote: libLazy.remote, + credentialsId: libLazy.credentialsId + ]) ) // Load Jenkins shared libraries to customize this project def libCustom = [ - remote: 'ssh://git@code.in.digital-me.nl:2222/DEVops/JenkinsLibCustom.git', - branch: env.BRANCH_NAME, - credentialsId: 'bot-ci-dgm-rsa', + remote: 'ssh://git@code.in.digital-me.nl:2222/DEVops/JenkinsLibCustom.git', + branch: env.BRANCH_NAME, + credentialsId: 'bot-ci-dgm-rsa', ] library( - identifier: "libCustom@${libCustom.branch}", - retriever: modernSCM([ - $class: 'GitSCMSource', - remote: libCustom.remote, - credentialsId: libCustom.credentialsId - ]) + identifier: "libCustom@${libCustom.branch}", + retriever: modernSCM([ + $class: 'GitSCMSource', + remote: libCustom.remote, + credentialsId: libCustom.credentialsId + ]) ) // Define the remotes and the working and deploy branches @@ -58,144 +58,144 @@ // Initialize configuration lazyConfig( - name: 'dummy-jenkins-pl', - env: [ + name: 'dummy-jenkins-pl', + env: [ RELEASE: false, - DRYRUN: false, - VERSION: '0.0.1', - BUILD_DIR: 'target', - DEPLOY_USER: 'root', - DEPLOY_HOST_STST: 'bxtsvctwas002.boxtel', - DEPLOY_DIR: '/var/www/html/public/dummy-jenkins-pl', - DEPLOY_CRED: 'bot-ci-dgm', - ], - inLabels: [ 'ubuntu-16', 'centos-7' ], - onLabels: [ default: 'master', docker: 'docker', mac: 'mac', android: 'android', ], - noPoll: '(.+_.+|release)', + DRYRUN: false, + VERSION: '0.0.1', + BUILD_DIR: 'target', + DEPLOY_USER: 'root', + DEPLOY_HOST_STST: 'bxtsvctwas002.boxtel', + DEPLOY_DIR: '/var/www/html/public/dummy-jenkins-pl', + DEPLOY_CRED: 'bot-ci-dgm', + ], + inLabels: [ 'ubuntu-16', 'centos-7' ], + onLabels: [ default: 'master', docker: 'docker', mac: 'mac', android: 'android', ], + noPoll: '(.+_.+|release)', ) lazyStage { - name = 'validate' - tasks = [ - [ - pre: { - def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') - currentBuild.displayName = "#${env.BUILD_NUMBER} ${currentVersion}" - }, - run: { - echo "This is my first task" - }, - ], - [ run: { echo "This is my second task" }, in: '*', on: 'docker' ], - [ run: "third.sh -v", in: [ 'ubuntu-16', 'centos-7'], on: 'docker',], - [ run: [ "fourth-a.sh -v -m c", "fourth-b.sh -v -m d"], on: 'mac' ], - [ run: [ "fourth-a.sh -v -m e", "fourth-b.sh -v -m f"], on: 'android' ], - ] + name = 'validate' + tasks = [ + [ + pre: { + def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + currentBuild.displayName = "#${env.BUILD_NUMBER} ${currentVersion}" + }, + run: { + echo "This is my first task" + }, + ], + [ run: { echo "This is my second task" }, in: '*', on: 'docker' ], + [ run: "third.sh -v", in: [ 'ubuntu-16', 'centos-7'], on: 'docker',], + [ run: [ "fourth-a.sh -v -m c", "fourth-b.sh -v -m d"], on: 'mac' ], + [ run: [ "fourth-a.sh -v -m e", "fourth-b.sh -v -m f"], on: 'android' ], + ] } lazyStage { - name = 'test' - tasks = [ - [ run: { echo "This is my fith task" }, ], - [ - run: { echo "This is my sixth task" }, - in: '*', on: 'docker' - ], - [ - run: [ 'junit.sh', 'jmeter.sh', ], - in: '*', on: 'docker', - post: { echo 'Archiving test reports' }, - ], - ] + name = 'test' + tasks = [ + [ run: { echo "This is my fith task" }, ], + [ + run: { echo "This is my sixth task" }, + in: '*', on: 'docker' + ], + [ + run: [ 'junit.sh', 'jmeter.sh', ], + in: '*', on: 'docker', + post: { echo 'Archiving test reports' }, + ], + ] } lazyStage { - name = 'package' - tasks = [ -// [ run: { echo "Building packages"; echo "Archive packages"; }, on: 'windows', ] -// [ run: { echo "Building packages"; echo "Archive packages"; }, on: 'mac', ] - [ - run: { - echo "Building packages"; - sh "mkdir -p ${env.BUILD_DIR} && echo 'testpkg' > ${env.BUILD_DIR}/\${LAZY_LABEL}.pkg" - }, - in: [ 'ubuntu-16', 'centos-7', ], - on: 'docker', - post: { - echo "Archiving packages" - archiveArtifacts(artifacts: "${env.BUILD_DIR}/**", allowEmptyArchive: false) - }, - ], - ] + name = 'package' + tasks = [ +// [ run: { echo "Building packages"; echo "Archive packages"; }, on: 'windows', ] +// [ run: { echo "Building packages"; echo "Archive packages"; }, on: 'mac', ] + [ + run: { + echo "Building packages"; + sh "mkdir -p ${env.BUILD_DIR} && echo 'testpkg' > ${env.BUILD_DIR}/\${LAZY_LABEL}.pkg" + }, + in: [ 'ubuntu-16', 'centos-7', ], + on: 'docker', + post: { + echo "Archiving packages" + archiveArtifacts(artifacts: "${env.BUILD_DIR}/**", allowEmptyArchive: false) + }, + ], + ] } // 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 string to be use for the next release', name: 'VERSION')] - ] - tasks = [ - pre: { - def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') - gitAuth('bot-ci-dgm-rsa', { - // Define next version based on optional input - // TODO: impelement/import a generic helper for semantic versionning - def nextVersion = 'new' - if (env.lazyInput) { - nextVersion = env.lazyInput - } - // Merge master into release branch - gitMerge(workingBranch, releaseBranch) - // Bump version and tag the release branch before deploying - sh("git checkout ${releaseBranch}") - writeFile(encoding: 'UTF-8', text: nextVersion, file: 'version.txt') - gitCommit("Update version to ${nextVersion}", 'version.txt') - }) - 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}") - }, - post: { - gitAuth('bot-ci-dgm-rsa', { - gitTag("${currentVersion}", remote) - gitPush(remote, releaseBranch) - }) - archiveArtifacts(artifacts: "${env.BUILD_DIR}/**", allowEmptyArchive: false) - }, - in: [ 'ubuntu-16', 'centos-7', ], on: 'docker', - ] + 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 string to be use for the next release', name: 'VERSION')] + ] + tasks = [ + pre: { + def currentVersion = readFile(encoding: 'UTF-8', file: 'version.txt') + gitAuth('bot-ci-dgm-rsa', { + // Define next version based on optional input + // TODO: impelement/import a generic helper for semantic versionning + def nextVersion = 'new' + if (env.lazyInput) { + nextVersion = env.lazyInput + } + // Merge master into release branch + gitMerge(workingBranch, releaseBranch) + // Bump version and tag the release branch before deploying + sh("git checkout ${releaseBranch}") + writeFile(encoding: 'UTF-8', text: nextVersion, file: 'version.txt') + gitCommit("Update version to ${nextVersion}", 'version.txt') + }) + 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}") + }, + post: { + gitAuth('bot-ci-dgm-rsa', { + gitTag("${currentVersion}", remote) + gitPush(remote, releaseBranch) + }) + archiveArtifacts(artifacts: "${env.BUILD_DIR}/**", allowEmptyArchive: false) + }, + in: [ 'ubuntu-16', 'centos-7', ], on: 'docker', + ] } lazyStage { - name = 'publish' - onlyif = ( env.LAZY_BRANCH == 'master' || lazyConfig.env.RELEASE ) - input = 'Publish?' - 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) - } - }, - ], - ] + name = 'publish' + onlyif = ( env.LAZY_BRANCH == 'master' || lazyConfig.env.RELEASE ) + input = 'Publish?' + 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) + } + }, + ], + ] }