-
Notifications
You must be signed in to change notification settings - Fork 81
/
Jenkinsfile
177 lines (153 loc) · 6.17 KB
/
Jenkinsfile
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
def now = new Date()
def currentDate = now.format("yyyy-MM-dd", TimeZone.getTimeZone('UTC'))
def buildTag = (!params.gitMerge)?"("+params.releaseBranch+")":"";
def zipFileName = "BuildFree-"+params.buildVersion+"-RC"+buildTag+".zip"
if(params.gitMerge) {
zipFileName = "BuildFree-"+params.buildVersion+".zip"
}
def zipFilePath = "/tmp/"+zipFileName
def today = new Date();
def releaseDate = today.format( 'yyyy-MM-dd' );
def changelog = params.changelog.replaceAll('"','\"');
def discordFooter = "Version ${params.buildVersion}\n Editor Version: ${params.editorVersion}\n Release Branch: ${params.releaseBranch}"
env.BUILD_FOLDER_PATH = "/tmp/brizy"
pipeline {
options {
skipDefaultCheckout()
}
agent any
environment {
GITHUB_TOKEN = credentials('git-token')
SUBVERSION_TOKEN = credentials('svn-secret')
DISCORD_WEBHOOK_URL = credentials('discord-webhook')
S3_BUCKET_NAME = credentials('s3-bucket-name')
}
stages {
stage('Verifying requested version') {
steps {
script {
if(folderExist(params.brizySvnPath+"/tags/"+params.buildVersion)) {
error("Build failed because this version is already built.")
}
}
}
}
stage('CheckOut') {
steps {
sshagent (credentials: ['ssh_with_passphrase_provided']) {
sh("""
if git rev-parse --git-dir > /dev/null 2>&1; then
echo "The repo is already cloned"
./jenkins/reset-repo.sh ./
git checkout -t origin/${params.releaseBranch}
else
git config --global user.email "[email protected]
git config --global user.name "Jenkins Jenkinovici
git clone [email protected]:ThemeFuse/Brizy.git ./
fi
""")
}
}
}
stage('Prepare Composer') {
steps {
sh('./jenkins/composer.sh $GITHUB_TOKEN')
}
}
stage('Build editor client') {
steps {
sh "./jenkins/build-editor-client.sh ./public/editor-client"
}
}
stage('Prepare the build') {
steps {
sh "./jenkins/version-update.sh ${params.buildVersion} ${params.minProVersion} ${params.editorVersion} ${params.syncVersion}"
sh "./jenkins/update-tested-version.sh README.md readme.txt"
}
}
stage('Prepare i18n files') {
steps {
sh "./jenkins/i18n.sh"
}
}
stage('Prepare changelog') {
when {
expression { return params.svnCommit }
}
steps {
writeFile file: 'changelog.txt', text: "\n= ${params.buildVersion} - ${releaseDate} =\n"+params.changelog+"\n"
writeFile file: 'changelog.md', text: "\n### ${params.buildVersion} - ${releaseDate}\n"+params.changelog+"\n"
sh "./jenkins/changelog-update.sh ./changelog.txt ./changelog.md"
sh "rm -rf changelog.txt changelog.md"
}
}
stage('Make a copy and clean the plugin') {
steps {
sh "./jenkins/clean-files.sh ${BUILD_FOLDER_PATH}"
}
}
stage('Create the Zip File') {
steps {
sh "./jenkins/prepare-zip.sh ${BUILD_FOLDER_PATH} \"$zipFilePath\""
}
}
stage('Prepare SVN') {
when {
expression { return params.svnCommit }
}
steps {
sh "./jenkins/prepare-svn.sh ${BUILD_FOLDER_PATH} ${params.brizySvnPath} ${params.buildVersion}"
}
}
stage('Clean temporary folders') {
steps {
sh "rm -rf ${BUILD_FOLDER_PATH}"
}
}
stage('Publish SVN changes') {
when {
expression { return params.svnCommit }
}
steps {
sh "cd " + params.brizySvnPath + " && svn commit --non-interactive --trust-server-cert --username themefusecom --password '$SUBVERSION_TOKEN' -m \"Version "+params.buildVersion+"\""
}
}
stage('Publish GIT changes') {
when {
expression { return params.gitMerge }
}
steps {
sshagent (credentials: ['ssh_with_passphrase_provided']) {
sh "./jenkins/git-publish.sh ${params.buildVersion} ${params.editorVersion} ${params.releaseBranch}"
}
}
}
}
post {
success{
sh "cp '${zipFilePath}' ./"
archiveArtifacts zipFileName
discordSend title: JOB_NAME, footer: discordFooter, link: env.BUILD_URL, result: currentBuild.currentResult, description: "Changelog: \n ${changelog}\n\n [Download]("+artifactUrl(env.S3_BUCKET_NAME,zipFileName)+")", webhookURL: env.DISCORD_WEBHOOK_URL
sh "rm '${zipFilePath}'"
sh "rm *.zip"
}
failure{
discordSend title: JOB_NAME, footer: discordFooter, link: env.BUILD_URL, result: currentBuild.currentResult, description: "Changelog: \n ${changelog}", webhookURL: env.DISCORD_WEBHOOK_URL
}
aborted{
discordSend title: JOB_NAME, footer: discordFooter, link: env.BUILD_URL, result: currentBuild.currentResult, description: "Changelog: \n ${changelog}", webhookURL: env.DISCORD_WEBHOOK_URL
}
always {
sshagent (credentials: ['ssh_with_passphrase_provided']) {
sh "./jenkins/reset-repo.sh ./"
}
}
}
}
def folderExist(path){
return sh(script: "test -d ${path} && echo 1 || echo 0", returnStdout: true).trim()=="1"
}
def artifactUrl(bucket,fileName) {
def jobNameUrlified = JOB_NAME.replaceAll(' ','+');
return "https://${bucket}.s3.amazonaws.com/${jobNameUrlified}/${BUILD_NUMBER}/artifacts/${fileName}"
}