diff --git a/Jenkinsfile b/Jenkinsfile index aacd32a..348b369 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,6 +19,9 @@ * limitations under the License. */ +// Define the remote and the branch used to release +def release = [ remote: 'origin', branch: 'devel_bear' ] + // Load Jenkins shared libraries common to all projects def libCmn = [ remote: 'https://code.in.digital-me.nl/git/DEVops/JenkinsLibLazy.git', @@ -38,6 +41,7 @@ // Initialize lazyConfig for this pipeline lazyConfig( name: 'DummyAnd', + nopoll: release['branch'], ) // Define a method to run Fastlane from the later lazyStages @@ -155,6 +159,39 @@ // Define lazyStages lazyStage { + name = 'prepare' + input = (owner.env.BRANCH_NAME == release['branch']) ? [ + message: 'Version name ?', + parameters: [string(defaultValue: '', description: 'Version name?', name: 'VERSION')] + ] : null + tasks = [ + run: { + echo("Lazy input = ${env.LAZY_INPUT}") + if (!env.LAZY_INPUT) error 'Not lazy input!' + def currentVersion = [ name: getVersion('versionName') as String, code: getVersion('versionCode') as Integer ] + echo("currentVersion = ${currentVersion.toString()}") + withGitPassword('bot-ci-dgm', { + if (env.BRANCH_NAME == release['branch']) { + echo("Git logs since last tag:\n" + gitLog()) + prepareChangelogs(currentVersion.code) + gitUpdateChangelogs(currentVersion.code, release['remote'], release['branch']) + if (env.LAZY_INPUT != '') { + gitUpdateVersion(env.LAZY_INPUT, currentVersion.code, release['remote'], release['branch']) + echo("newVersion = [name: ${env.LAZY_INPUT}, code: ${currentVersion.code}]" ) + } + } else { + sh(""" +git pull --quiet --rebase ${release['remote']} ${release['branch']} +git push --quiet ${release['remote']} ${env.BRANCH_NAME} + """) + } + }) + }, +on: 'android', + ] +} + +lazyStage { name = 'validate' tasks = [ run: { @@ -177,51 +214,45 @@ ] } -if (env.BRANCH_NAME == 'master') { - lazyStage { - name = 'release' - input = 'Release to alpha?' - tasks = [ - pre: { - unarchive(mapping:['app/build/outputs/apk/' : '.']) - sh("ls -lA app/build/outputs/apk") - }, - run: { env -> - def currentVersion = [ name: getVersion('versionName') as String, code: getVersion('versionCode') as Integer ] - def nextVersion = [ name: currentVersion.name, code: currentVersion.code + 1] - echo("currentVersion = ${currentVersion.toString()} / nextVersion = ${nextVersion.toString()}") - withGitPassword('bot-ci-dgm', { - echo("Git logs since last tag:\n" + gitLog()) - prepareChangelogs(currentVersion.code) - if ( env.DRYRUN != 'true' ) fastlane('android', 'alpha') - gitUpdateChangelogs(currentVersion.code) - gitTag("${currentVersion.name}-${currentVersion.code}") - gitUpdateVersion(nextVersion.name, nextVersion.code) - }) - }, - on: 'android', - ] - } - - lazyStage { - name = 'acceptance' - input = 'Promote to beta?' - tasks = [ - run: { env -> - if ( env.DRYRUN != 'true' ) fastlane('android', 'beta') - }, - on: 'android', - ] - } - - lazyStage { - name = 'production' - input = 'Promote to production?' - tasks = [ - run: { env -> - if ( env.DRYRUN != 'true' ) fastlane('android', 'production') - }, - on: 'android', - ] - } +if (env.BRANCH_NAME == release['branch']) { + lazyStage { + name = 'release' + tasks = [ + pre: { + unarchive(mapping:['app/build/outputs/apk/' : '.']) + sh("ls -lA app/build/outputs/apk") + }, + run: { + def currentVersion = [ name: getVersion('versionName') as String, code: getVersion('versionCode') as Integer ] + def nextVersion = [ name: currentVersion.name, code: currentVersion.code + 1] + echo("currentVersion = ${currentVersion.toString()} / nextVersion = ${nextVersion.toString()}") + withGitPassword('bot-ci-dgm', { + if ( env.DRYRUN != 'true' ) fastlane('android', 'alpha') + gitTag("${currentVersion.name}-${currentVersion.code}") + gitUpdateVersion(nextVersion.name, nextVersion.code, release['remote'], release['branch']) + }) + }, + on: 'android', + ] + } + + lazyStage { + name = 'acceptance' + input = 'Promote alpha to beta?' + tasks = [ + run: { + if ( env.DRYRUN != 'true' ) fastlane('android', 'beta') + } + ] + } + + lazyStage { + name = 'production' + input = 'Promote beta to production?' + tasks = [ + run: { + if ( env.DRYRUN != 'true' ) fastlane('android', 'production') + } + ] + } }