modify .env settings using Jenkins params
Signed-off-by: Jakub Sokołowski <jakub@status.im> Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
parent
316a50b032
commit
55abf20645
|
@ -80,7 +80,7 @@ pipeline {
|
|||
}
|
||||
stage('Bundle') {
|
||||
steps {
|
||||
script { apk = mobile.android.bundle(btype) }
|
||||
script { apk = mobile.android.bundle() }
|
||||
}
|
||||
}
|
||||
stage('Archive') {
|
||||
|
|
|
@ -14,7 +14,6 @@ pipeline {
|
|||
))
|
||||
}
|
||||
|
||||
|
||||
stages {
|
||||
stage('Prep') {
|
||||
steps { script {
|
||||
|
|
|
@ -65,7 +65,7 @@ pipeline {
|
|||
}
|
||||
stage('Bundle') {
|
||||
steps {
|
||||
script { api = mobile.ios.bundle(btype) }
|
||||
script { api = mobile.ios.bundle() }
|
||||
}
|
||||
}
|
||||
stage('Archive') {
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
utils = load 'ci/utils.groovy'
|
||||
|
||||
def bundle(type = 'nightly') {
|
||||
def bundle() {
|
||||
def btype = utils.getBuildType()
|
||||
/* Disable Gradle Daemon https://stackoverflow.com/questions/38710327/jenkins-builds-fail-using-the-gradle-daemon */
|
||||
def gradleOpt = "-PbuildUrl='${currentBuild.absoluteUrl}' -Dorg.gradle.daemon=false "
|
||||
def target = "release"
|
||||
|
||||
if (type in ['pr', 'e2e']) {
|
||||
if (btype in ['pr', 'e2e']) {
|
||||
/* PR builds shouldn't replace normal releases */
|
||||
target = 'pr'
|
||||
} else if (type == 'release') {
|
||||
} else if (btype == 'release') {
|
||||
gradleOpt += "-PreleaseVersion='${utils.getVersion('mobile_files')}'"
|
||||
}
|
||||
dir('android') {
|
||||
|
@ -28,7 +29,7 @@ def bundle(type = 'nightly') {
|
|||
}
|
||||
sh 'find android/app/build/outputs/apk'
|
||||
def outApk = "android/app/build/outputs/apk/${target}/app-${target}.apk"
|
||||
def pkg = utils.pkgFilename(type, 'apk')
|
||||
def pkg = utils.pkgFilename(btype, 'apk')
|
||||
/* rename for upload */
|
||||
sh "cp ${outApk} ${pkg}"
|
||||
/* necessary for Fastlane */
|
||||
|
|
|
@ -53,22 +53,15 @@ def prepNixEnvironment() {
|
|||
}
|
||||
|
||||
def prep(type = 'nightly') {
|
||||
/* build/downloads all nix deps in advance */
|
||||
prepNixEnvironment()
|
||||
|
||||
/* rebase unless this is a release build */
|
||||
utils.doGitRebase()
|
||||
/* ensure that we start from a known state */
|
||||
sh 'make clean'
|
||||
/* select type of build */
|
||||
switch (type) {
|
||||
case 'nightly':
|
||||
sh 'cp .env.nightly .env'; break
|
||||
case 'release':
|
||||
sh 'cp .env.prod .env'; break
|
||||
case 'e2e':
|
||||
sh 'cp .env.e2e .env'; break
|
||||
default:
|
||||
sh 'cp .env.jenkins .env'; break
|
||||
}
|
||||
/* pick right .env and update from params */
|
||||
utils.updateEnv(type)
|
||||
|
||||
if (env.TARGET_PLATFORM == 'android' || env.TARGET_PLATFORM == 'ios') {
|
||||
/* Run at start to void mismatched numbers */
|
||||
utils.genBuildNumber()
|
||||
|
|
|
@ -6,12 +6,10 @@ def plutil(name, value) {
|
|||
"""
|
||||
}
|
||||
|
||||
def bundle(type) {
|
||||
if (!type) {
|
||||
type = utils.getBuildType()
|
||||
}
|
||||
def bundle() {
|
||||
def btype = utils.getBuildType()
|
||||
def target
|
||||
switch (type) {
|
||||
switch (btype) {
|
||||
case 'release': target = 'release'; break;
|
||||
case 'testflight': target = 'release'; break;
|
||||
case 'e2e': target = 'e2e'; break;
|
||||
|
@ -39,14 +37,14 @@ def bundle(type) {
|
|||
}
|
||||
/* rename built file for uploads and archivization */
|
||||
def pkg = ''
|
||||
if (type == 'release') {
|
||||
if (btype == 'release') {
|
||||
pkg = utils.pkgFilename('release', 'ipa')
|
||||
sh "cp status_appstore/StatusIm.ipa ${pkg}"
|
||||
} else if (type == 'e2e') {
|
||||
} else if (btype == 'e2e') {
|
||||
pkg = utils.pkgFilename('e2e', 'app.zip')
|
||||
sh "cp status-e2e/StatusIm.app.zip ${pkg}"
|
||||
} else if (type != 'testflight') {
|
||||
pkg = utils.pkgFilename(type, 'ipa')
|
||||
} else if (btype != 'testflight') {
|
||||
pkg = utils.pkgFilename(btype, 'ipa')
|
||||
sh "cp status-adhoc/StatusIm.ipa ${pkg}"
|
||||
}
|
||||
/* necessary for Diawi upload */
|
||||
|
|
|
@ -28,21 +28,35 @@ def abortPreviousRunningBuilds() {
|
|||
}
|
||||
}
|
||||
|
||||
def Build(name = null, buildType = null) {
|
||||
def Build(name = null) {
|
||||
/**
|
||||
* Generate parameters to pass from current params
|
||||
* This allows utils.updateEnv() to work in sub-jobs
|
||||
**/
|
||||
parameters = params.keySet().collectEntries { key ->
|
||||
[(key): [
|
||||
name: key,
|
||||
value: params.get(key),
|
||||
$class: 'StringParameterValue'
|
||||
]]
|
||||
}
|
||||
/* default to current build type */
|
||||
buildType = buildType ? buildType : utils.getBuildType()
|
||||
parameters['BUILD_TYPE'].value = utils.getBuildType()
|
||||
/* need to drop origin/ to match definitions of child jobs */
|
||||
def branchName = utils.branchName()
|
||||
parameters['BRANCH'].value = utils.branchName()
|
||||
/* necessary for updating GitHub PRs */
|
||||
parameters['CHANGE_ID'] = [
|
||||
name: 'CHANGE_ID',
|
||||
value: env.CHANGE_ID,
|
||||
$class: 'StringParameterValue'
|
||||
]
|
||||
/* always pass the BRANCH and BUILD_TYPE params with current branch */
|
||||
def b = build(
|
||||
job: name,
|
||||
/* this allows us to analize the job even after failure */
|
||||
propagate: false,
|
||||
parameters: [
|
||||
[name: 'BRANCH', value: branchName, $class: 'StringParameterValue'],
|
||||
[name: 'BUILD_TYPE', value: buildType, $class: 'StringParameterValue'],
|
||||
[name: 'CHANGE_ID', value: env.CHANGE_ID, $class: 'StringParameterValue'],
|
||||
])
|
||||
parameters: parameters.values()
|
||||
)
|
||||
/* BlueOcean seems to not show child-build links */
|
||||
println "Build: ${b.getAbsoluteUrl()} (${b.result})"
|
||||
if (b.result != 'SUCCESS') {
|
||||
|
|
|
@ -154,7 +154,7 @@ def getBuildType() {
|
|||
if (jobName.contains('e2e')) {
|
||||
return 'e2e'
|
||||
}
|
||||
if (jobName.startsWith('status-react/pull requests')) {
|
||||
if (jobName.startsWith('status-react/prs')) {
|
||||
return 'pr'
|
||||
}
|
||||
if (jobName.startsWith('status-react/nightly')) {
|
||||
|
@ -185,4 +185,29 @@ def changeId() {
|
|||
return changeId
|
||||
}
|
||||
|
||||
def updateEnv(type) {
|
||||
def envFile = "${env.WORKSPACE}/.env"
|
||||
/* select .env based on type of build */
|
||||
def selectedEnv = '.env.jenkins'
|
||||
switch (type) {
|
||||
case 'nightly': selectedEnv = '.env.nightly'; break
|
||||
case 'release': selectedEnv = '.env.prod'; break
|
||||
case 'e2e': selectedEnv = '.env.e2e'; break
|
||||
}
|
||||
sh "cp ${selectedEnv} .env"
|
||||
/* find a list of .env settings to check for them in params */
|
||||
def envContents = readFile(envFile)
|
||||
def envLines = envContents.split()
|
||||
def envVars = envLines.collect { it.split('=').first() }
|
||||
/* for each var available in params modify the .env file */
|
||||
envVars.each { var ->
|
||||
if (params.get(var)) { /* var exists in params and is not empty */
|
||||
println("Changing setting: ${var}=${params.get(var)}")
|
||||
sh "sed -i'.bkp' 's/${var}=.*/${var}=${params.get(var)}/' ${envFile}"
|
||||
}
|
||||
}
|
||||
/* show contents for debugging purposes */
|
||||
sh "cat ${envFile}"
|
||||
}
|
||||
|
||||
return this
|
||||
|
|
Loading…
Reference in New Issue