#!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 libLazy = [
remote: 'https://code.in.digital-me.nl/git/DEVops/JenkinsLibLazy.git',
branch: 'master',
credentialsId: null,
]
library(
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: 'master',
credentialsId: 'bot-ci-dgm-rsa',
]
library(
identifier: "libCustom@${libCustom.branch}",
retriever: modernSCM([
$class: 'GitSCMSource',
remote: libCustom.remote,
credentialsId: libCustom.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: 'master' ]
def releaseTo = [ remote: 'origin', branch: 'master' ]
// Define the directory where the package will be build
def buildDir = 'app/build/outputs/apk'
// Initialize lazyConfig for this pipeline
lazyConfig(
name: 'DummyAnd',
env: [ RELEASE: false, ],
noPoll: '(.+_|release-).+',
)
// Define lazyStages
lazyStage {
name = 'validate'
onlyif = (!( lazyConfig['branch'] ==~ /^release-.+/ ))
tasks = [
run: {
fastLane('android', 'test')
},
on: 'android',
]
}
lazyStage {
name = 'package'
tasks = [
run: {
fastLane('android', 'build')
},
post: {
archiveArtifacts(artifacts: "${buildDir}/**", allowEmptyArchive: false)
},
on: 'android',
]
}
// Release stage only only if criteria are met
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 string',
parameters: [string(defaultValue: '', description: 'Version string to be release (no build number)', name: 'VERSION')]
]
tasks = [
run: {
def currentVersion = androidVersion()
echo("currentVersion = ${currentVersion.toString()}")
gitAuth('bot-ci-dgm', {
// Fork a release branch as requested
echo("Git logs since last tag:\n" + gitLog())
def nextVersion = [ string: currentVersion.string, number: currentVersion.number + 1 ]
if (env.lazyInput) {
nextVersion = [ string: env.lazyInput, number: nextVersion.number ]
}
sh("git checkout -b release-${nextVersion.string}")
androidVersion(nextVersion)
nextVersion = androidVersion() // Just to catch any problem
echo("nextVersion = ${nextVersion.toString()}" )
fastChangeLogs(nextVersion.number, 'android')
gitCommit("Provide changelogs for version ${nextVersion.number}", 'fastlane/metadata/android')
gitCommit("Update version to ${nextVersion.string}-${nextVersion.number}", 'app/build.gradle')
gitPush(releaseFrom['remote'], "release-${nextVersion.string}")
})
},
on: 'android',
]
}
// From systemtest to production, only for release branches
lazyStage {
name = 'systemtest'
onlyif = ( lazyConfig['branch'] ==~ /^release-.+/ )
tasks = [
pre: {
unarchive(mapping:["${buildDir}/" : '.'])
sh("ls -lA ${buildDir}")
},
run: {
def currentVersion = androidVersion()
echo("currentVersion = ${currentVersion.toString()}")
if ( !lazyConfig.env.DRYRUN ) fastLane('android', 'alpha')
gitAuth('bot-ci-dgm', {
gitMerge(
"${lazyConfig['branch']}",
"${releaseFrom['branch']}",
"Merge changes from ${currentVersion.string}-${currentVersion.number} back into ${releaseFrom['branch']}"
)
gitPush(releaseFrom['remote'], releaseFrom['branch'])
gitTag("${currentVersion.string}-${currentVersion.number}", releaseTo['remote'])
})
},
on: 'android',
]
}
lazyStage {
name = 'acceptance'
onlyif = ( lazyConfig['branch'] ==~ /^release-.+/ )
input = 'Promote alpha to beta?'
tasks = [
pre: {
unarchive(mapping:["${buildDir}/" : '.'])
sh("ls -lA ${buildDir}")
},
run: {
if ( !lazyConfig.env.DRYRUN ) fastLane('android', 'beta')/*
},
on: 'android',
]
}
lazyStage {
name = 'production'
onlyif = ( lazyConfig['branch'] ==~ /^release-.+/ )
input = 'Promote beta to production?'
tasks = [
pre: {
unarchive(mapping:["${buildDir}/" : '.'])
sh("ls -lA ${buildDir}")
},
run: {
if ( !lazyConfig.env.DRYRUN ) fastLane('android', 'production')*/
def currentVersion = androidVersion()
echo("currentVersion = ${currentVersion.toString()}")
gitAuth('bot-ci-dgm', {
gitMerge(
"${lazyConfig['branch']}",
"${releaseTo['branch']}",
"Merge changes from ${currentVersion.string}-${currentVersion.number} into ${releaseTo['branch']}"
)
gitPush(releaseTo['remote'], releaseTo['branch'])
})
},
on: 'android',
]
}