This repository has been archived by the owner on Jan 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile-release
82 lines (67 loc) · 2.86 KB
/
Jenkinsfile-release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: "1"))
disableConcurrentBuilds()
disableResume()
timestamps()
timeout(time: 30, unit: 'MINUTES')
}
environment {
GIT_PUSH_BRANCH = "develop"
GIT_CONFIG_USER_NAME = "Jenkins"
GIT_CONFIG_USER_MAIL = "contact+jenkins@c-henry.fr"
GIT_AUTH = credentials "gitlab-jenkins-release"
}
parameters {
string defaultValue: "", description: "", name: "VERSION", trim: true
text defaultValue: "", description: "", name: "CHANGELOG"
}
stages {
stage("Updating versionCode and versionName") {
steps {
script {
if(params.VERSION.isEmpty()) error("Parameter VERSION must not be empty")
if(params.CHANGELOG.isEmpty()) error("Parameter CHANGELOG must not be empty")
def filePath = "$WORKSPACE/.versions.properties"
def props = readProperties file: filePath
env.VERSION_CODE = Integer.parseInt("${props.versionCode}".trim()) + 1
props.versionCode = env.VERSION_CODE
props.versionName = params.VERSION
def propsString = props.collect { k, v -> "$k = $v"}.join("\n")
writeFile file: filePath, text: normalizeString(propsString)
sh "git add $filePath"
}
}
}
stage("Creating new changelog for version") {
steps {
script {
def changelogPath = "$WORKSPACE/fastlane/metadata/android/en-US/changelogs/${env.VERSION_CODE}.txt"
def file = new File(changelogPath)
file.write(normalizeString(params.CHANGELOG), "utf-8")
sh "git add $changelogPath"
}
}
}
stage("Commit and push") {
steps {
script {
def shellFctn = "echo username=${'$'}GIT_AUTH_USR; echo password=${'$'}GIT_AUTH_PSW;"
def versionSummary = "Release v${params.VERSION}"
sh("""
git config --local credential.helper "!f() { $shellFctn }; f"
git config --global user.name ${env.GIT_CONFIG_USER_NAME}
git config --global user.email ${env.GIT_CONFIG_USER_MAIL}
git commit -am '[Jenkins CI] $versionSummary'
git tag -f -m "$versionSummary\n\n${normalizeString(params.CHANGELOG)}" v${params.VERSION}
git push --tags origin HEAD:${env.GIT_PUSH_BRANCH}
""")
}
}
}
}
}
String normalizeString(String changelog) {
return changelog.endsWith("\n") ? changelog : "${changelog}\n"
}