#!groovy
/*
* This work is protected under copyright law in the Kingdom of
* The Netherlands. The rules of the Berne Convention for the
* Protection of Literary and Artistic Works apply.
* Digital Me B.V. is the copyright owner.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Load Jenkins shared libraries common to all projects
def libCmn = [
remote: 'https://code.in.digital-me.nl/git/DEVops/JenkinsLibLazy.git',
branch: 'devel_bear',
credentialsId: null,
]
library(
identifier: "libCmn@${libCmn.branch}",
retriever: modernSCM([
$class: 'GitSCMSource',
remote: libCmn.remote,
credentialsId: libCmn.credentialsId
])
)
// Load Jenkins shared libraries to customize this project
def libCst = [
remote: 'ssh://git@code.in.digital-me.nl:2222/DEVops/JenkinsLibCustom.git',
branch: 'devel_bear',
credentialsId: 'bot-ci-dgm-rsa',
]
library(
identifier: "libCst@${libCst.branch}",
retriever: modernSCM([
$class: 'GitSCMSource',
remote: libCst.remote,
credentialsId: libCst.credentialsId
])
)
// Define the remotes and the branches used to release from and to
// Using master for both since we don't want a devel branch
// And wecan rely on tagging for production state
def releaseFrom = [ remote: 'origin', branch: 'devel_bear' ]
def releaseTo = [ remote: 'origin', branch: 'devel_bear' ]
// Initialize lazyConfig for this pipeline
lazyConfig(
name: 'DummyAnd',
nopoll: '.+_.+',
)
// Define lazyStages
lazyStage {
name = 'validate'
tasks = [
run: {
fastlane('android', 'test')
},
on: 'android',
]
}
lazyStage {
name = 'package'
tasks = [
run: {
fastlane('android', 'build')
},
post: {
archiveArtifacts(artifacts: 'app/build/outputs/apk/**', allowEmptyArchive: false)
},
on: 'android',
]
}
// 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?', 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-${env.LAZY_INPUT}")
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')
lazyGit.withPassword('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'])
})
},
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 = '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'])
gitTag("${currentVersion.name}", releaseTo['remote'])
})
},
on: 'android',
]
}
}