diff --git a/Jenkinsfile b/Jenkinsfile index bb8cfa9..109da68 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,34 +20,34 @@ */ // Load Jenkins shared libraries common to all projects -def libCmn = [ +def libLazy = [ remote: 'https://code.in.digital-me.nl/git/DEVops/JenkinsLibLazy.git', branch: 'master', credentialsId: null, ] library( - identifier: "libCmn@${libCmn.branch}", + identifier: "libLazy@${libLazy.branch}", retriever: modernSCM([ $class: 'GitSCMSource', - remote: libCmn.remote, - credentialsId: libCmn.credentialsId + remote: libLazy.remote, + credentialsId: libLazy.credentialsId ]) ) // Load Jenkins shared libraries to customize this project -def libCst = [ +def libCustom = [ remote: 'ssh://git@code.in.digital-me.nl:2222/DEVops/JenkinsLibCustom.git', branch: 'master', credentialsId: 'bot-ci-dgm-rsa', ] library( - identifier: "libCst@${libCst.branch}", + identifier: "libCustom@${libCustom.branch}", retriever: modernSCM([ $class: 'GitSCMSource', - remote: libCst.remote, - credentialsId: libCst.credentialsId + remote: libCustom.remote, + credentialsId: libCustom.credentialsId ]) ) @@ -60,12 +60,14 @@ // Initialize lazyConfig for this pipeline lazyConfig( name: 'DummyAnd', - nopoll: '.+_.+', + env: [ RELEASE: false, ], + noPoll: '.+_.+', ) // Define lazyStages lazyStage { name = 'validate' + onlyif = (!( lazyConfig.branch ==~ /^release-.+/ )) tasks = [ run: { fastlane('android', 'test') @@ -88,104 +90,104 @@ } // Release stage only only if criteria are met -if (env.BRANCH_NAME == releaseFrom['branch'] && env.env ==~ /RELEASE=true/) { - lazyStage { - name = 'release' - // Ask version if release flag and set and we are in the branch to fork release from - input = [ - message: 'Version name', - parameters: [string(defaultValue: '', description: 'Version name to be release (no versionCode)', name: 'VERSION')] - ] - tasks = [ - run: { - def currentVersion = androidVersion() - echo("currentVersion = ${currentVersion.toString()}") - lazyGitPass('bot-ci-dgm', { - // Fork a release branch as requested - echo("Git logs since last tag:\n" + gitLog()) - def nextVersion = [ name: currentVersion.name, code: currentVersion.code + 1 ] - if (env.lazyInput) { - nextVersion = [ name: env.lazyInput, code: nextVersion.code ] - } - sh("git checkout -b release-${nextVersion.name}") - androidVersion(nextVersion) - nextVersion = androidVersion() // Just to catch any problem - echo("nextVersion = ${nextVersion.toString()}" ) - androidChangeLogs(nextVersion.code) - gitCommit("Provide changelogs for version ${nextVersion.code}", 'fastlane/metadata/android') - gitCommit("Update version to ${nextVersion.name}-${nextVersion.code}", 'app/build.gradle') - gitPush(releaseFrom['remote'], "release-${nextVersion.name}") - }) - }, - on: 'android', - ] - } +lazyStage { + name = 'release' + onlyif = ( lazyConfig.branch == releaseFrom['branch'] && lazyConfig.env.RELEASE ) + // Ask version if release flag and set and we are in the branch to fork release from + input = [ + message: 'Version name', + parameters: [string(defaultValue: '', description: 'Version name to be release (no versionCode)', name: 'VERSION')] + ] + tasks = [ + run: { + def currentVersion = androidVersion() + echo("currentVersion = ${currentVersion.toString()}") + lazyGitPass('bot-ci-dgm', { + // Fork a release branch as requested + echo("Git logs since last tag:\n" + gitLog()) + def nextVersion = [ name: currentVersion.name, code: currentVersion.code + 1 ] + if (env.lazyInput) { + nextVersion = [ name: env.lazyInput, code: nextVersion.code ] + } + sh("git checkout -b release-${nextVersion.name}") + androidVersion(nextVersion) + nextVersion = androidVersion() // Just to catch any problem + echo("nextVersion = ${nextVersion.toString()}" ) + androidChangeLogs(nextVersion.code) + gitCommit("Provide changelogs for version ${nextVersion.code}", 'fastlane/metadata/android') + gitCommit("Update version to ${nextVersion.name}-${nextVersion.code}", 'app/build.gradle') + gitPush(releaseFrom['remote'], "release-${nextVersion.name}") + }) + }, + on: 'android', + ] } // From systemtest to production, only for release branches -if (env.BRANCH_NAME ==~ /^release-.*/) { - lazyStage { - name = 'systemtest' - tasks = [ - pre: { - unarchive(mapping:['app/build/outputs/apk/' : '.']) - sh("ls -lA app/build/outputs/apk") - }, - run: { - def currentVersion = androidVersion() - echo("currentVersion = ${currentVersion.toString()}") - if ( env.DRYRUN != 'true' ) fastlane('android', 'alpha') - lazyGitPass('bot-ci-dgm', { - gitMerge( - "${env.BRANCH_NAME}", - "${releaseFrom['branch']}", - "Merge changes from ${currentVersion['name']}-${currentVersion['code']} back into ${releaseFrom['branch']}" - ) - gitPush(releaseFrom['remote'], releaseFrom['branch']) - gitTag("${currentVersion.name}-${currentVersion.code}", releaseTo['remote']) - }) - }, - on: 'android', - ] - } +lazyStage { + name = 'systemtest' + onlyif = ( lazyConfig.branch ==~ /^release-.+/ ) + tasks = [ + pre: { + unarchive(mapping:['app/build/outputs/apk/' : '.']) + sh("ls -lA app/build/outputs/apk") + }, + run: { + def currentVersion = androidVersion() + echo("currentVersion = ${currentVersion.toString()}") + if ( env.DRYRUN != 'true' ) fastlane('android', 'alpha') + lazyGitPass('bot-ci-dgm', { + gitMerge( + "${lazyConfig.branch}", + "${releaseFrom['branch']}", + "Merge changes from ${currentVersion['name']}-${currentVersion['code']} back into ${releaseFrom['branch']}" + ) + gitPush(releaseFrom['remote'], releaseFrom['branch']) + gitTag("${currentVersion.name}-${currentVersion.code}", releaseTo['remote']) + }) + }, + on: 'android', + ] +} - lazyStage { - name = 'acceptance' - input = 'Promote alpha to beta?' - tasks = [ - pre: { - unarchive(mapping:['app/build/outputs/apk/' : '.']) - sh("ls -lA app/build/outputs/apk") - }, - run: { - if ( env.DRYRUN != 'true' ) fastlane('android', 'beta')/* - }, - on: 'android', - ] - } +lazyStage { + name = 'acceptance' + onlyif = ( lazyConfig.branch ==~ /^release-.+/ ) + input = 'Promote alpha to beta?' + tasks = [ + pre: { + unarchive(mapping:['app/build/outputs/apk/' : '.']) + sh("ls -lA app/build/outputs/apk") + }, + run: { + if ( lazyConfig.env.DRYRUN ) fastlane('android', 'beta')/* + }, + on: 'android', + ] +} - lazyStage { - name = 'production' - input = 'Promote beta to production?' - tasks = [ - pre: { - unarchive(mapping:['app/build/outputs/apk/' : '.']) - sh("ls -lA app/build/outputs/apk") - }, - run: { - if ( env.DRYRUN != 'true' ) fastlane('android', 'production')*/ - def currentVersion = androidVersion() - echo("currentVersion = ${currentVersion.toString()}") - lazyGitPass('bot-ci-dgm', { - gitMerge( - "${env.BRANCH_NAME}", - "${releaseTo['branch']}", - "Merge changes from ${currentVersion['name']}-${currentVersion['code']} into ${releaseTo['branch']}" - ) - gitPush(releaseTo['remote'], releaseTo['branch']) - }) - }, - on: 'android', - ] - } +lazyStage { + name = 'production' + onlyif = ( lazyConfig.branch ==~ /^release-.+/ ) + input = 'Promote beta to production?' + tasks = [ + pre: { + unarchive(mapping:['app/build/outputs/apk/' : '.']) + sh("ls -lA app/build/outputs/apk") + }, + run: { + if ( lazyConfig.env.DRYRUN ) fastlane('android', 'production')*/ + def currentVersion = androidVersion() + echo("currentVersion = ${currentVersion.toString()}") + lazyGitPass('bot-ci-dgm', { + gitMerge( + "${lazyConfig.branch}", + "${releaseTo['branch']}", + "Merge changes from ${currentVersion['name']}-${currentVersion['code']} into ${releaseTo['branch']}" + ) + gitPush(releaseTo['remote'], releaseTo['branch']) + }) + }, + on: 'android', + ] }