forked from pantheon-systems/example-drops-8-composer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-default-pantheon
186 lines (178 loc) · 5.67 KB
/
Jenkinsfile-default-pantheon
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
178
179
180
181
182
183
184
185
186
#!groovy
// Include Xeno Global Library
@Library('XENO_JENKINS') _
def getLabel() {
// Which server to run this on.
return "php[5,7,71][a-d]"
}
def projectName() {
return "SITENAME"
}
// Choose the site name based on git name and if it is a Pull Request or branch.
def getSitename() {
// If xupdates branch we build on our staging servers.
if (env.BRANCH_NAME == 'xupdates') {
PREFIX = "${projectName()}-"
}
else {
PREFIX = ''
}
// Set the project name, most likely the git repo name.
if (env.CHANGE_BRANCH && !env.CHANGE_FORK){
return "${PREFIX}${env.CHANGE_BRANCH.toLowerCase()}"
}
else{
return "${PREFIX}${env.BRANCH_NAME.toLowerCase()}"
}
}
def getSlackname() {
return sh (
script: 'git --no-pager show -s --format=%ae',
returnStdout: true
).trim()
}
/**
* Get custom workspace path.
*/
def getCustomworkspace() {
if (env.BRANCH_NAME == 'xupdates') {
return "/var/www/${getSitename()}"
}
else {
return "/var/build/${projectName()}-${getSitename()}"
}
}
pipeline {
environment {
// Database backup name
X_DB_BACKUP = "SITENAME.sql.gz"
// Database User to use on the testing server
X_DB_USER = "SITENAME"
// The live URL, used for stage file proxy and WP find-replace
X_LIVE_DOMAIN = "https://SITENAME.com"
// Slack IDs for notification.
X_SLACK_NOTIFY = "<@here>"
// Slack Channel
X_SLACK_CHANNEL = "#other-deploys"
// Code paths for phpcs checks, space delimited
X_CODE = "web/modules/custom/"
// Code paths for phpcs ignore, comma delimited
X_IGNORE = "*css"
}
agent {
node {
label "${getLabel()}"
customWorkspace "${getCustomworkspace()}"
}
}
options {
// do not run more than one build per branch
disableConcurrentBuilds()
// lock based on branch name, pull requests use branch name
// lock resource: "${getSitename()}"
lock(resource: "SITENAME", inversePrecedence: true)
// timeout after 1 hours
timeout(time: 1, unit: 'HOURS')
// keep 7 jobs
buildDiscarder(logRotator(numToKeepStr: '7'))
skipDefaultCheckout()
}
stages {
stage("Checkout") {
steps {
milestone(2)
checkout scm
}
}
stage("Setup") {
when {
not {
anyOf {
branch 'master'
branch 'xupdates'
expression {
return !fileExists("/var/www/${getSitename()}/web/sites/default/settings.local.php")
}
}
}
}
steps {
milestone(5)
xenoBuildPantheon( "${projectName()}", "${getSitename()}", "${getLabel()}")
sh """
terminus connection:set ${projectName()}.${getSitename()} sftp
terminus remote:drush ${projectName()}.${getSitename()} -- updb -y
terminus remote:drush ${projectName()}.${getSitename()} -- cc drush
terminus remote:drush ${projectName()}.${getSitename()} -- cim -y
terminus remote:drush ${projectName()}.${getSitename()} -- cr
"""
}
}
stage('Updates') {
when {
branch 'xupdates'
}
steps {
xenoUpdateD8Pantheon( "${getSitename()}", env.X_DB_BACKUP, env.X_DB_USER, env.X_LIVE_DOMAIN, "${getLabel()}")
}
}
// @TODO Make this work but prevent it to run during initial creation.
// stage("Drupal") {
// steps {
// sh """
// composer install
// terminus connection:set ${projectName()}.${getSitename()} sftp
// terminus remote:drush ${projectName()}.${getSitename()} -- updb -y
// terminus remote:drush ${projectName()}.${getSitename()} -- cim -y
// """
// }
// }
stage("Tests") {
when {
not { branch 'jenkins' }
}
failFast true
parallel {
// stage('Behat') {
// steps {
// // behatD7("${getSitename()}") The site name to update the Bahat scripts with.
// behatD7web("${getSitename()}")
// }
// }
stage('PHPcs') {
steps {
// phpcs("Druapal|Wordpress", sitename, codePath, ignorePath)
phpcs("Drupal", "${getSitename()}", "${X_CODE}", "${X_IGNORE}")
}
}
}
}
stage ('Deploy Code') {
when {
branch 'master'
}
steps {
milestone(25)
slackNotify("No deploy configured. https://${getSitename()}.xenostaging.com", "${X_SLACK_CHANNEL}", 'good', "${X_SLACK_NOTIFY}", "${getSlackname()}")
// slackNotify("Ready to review and deploy. https://${getSitename()}.xenostaging.com", "${X_SLACK_CHANNEL}", 'good', "${X_SLACK_NOTIFY}", "${getSlackname()}")
// script {
// timeout(time:4, unit:'DAYS') { // expires in 4 days
// env.RELEASE_SCOPE = input message: 'Deploy to Production?', ok: 'Release!', submitterParameter: 'APPROVER'
// } // end timeout
// slackNotify("approved by ${env.RELEASE_SCOPE} and deploy started", "${X_SLACK_CHANNEL}", 'good', "${X_SLACK_NOTIFY}", "${getSlackname()}")
// }
}
}
}
post {
success {
slackNotify("Build Compete. https://${getSitename()}.xenostaging.com", "${X_SLACK_CHANNEL}", 'good', "${X_SLACK_NOTIFY}", "${getSlackname()}")
}
failure {
slackNotify("Build Failed. https://${getSitename()}.xenostaging.com", "${X_SLACK_CHANNEL}", 'danger', "${X_SLACK_NOTIFY}", "${getSlackname()}")
}
unstable {
slackNotify("Build is unstable. https://${getSitename()}.xenostaging.com", "${X_SLACK_CHANNEL}", 'warning', "${X_SLACK_NOTIFY}", "${getSlackname()}")
}
}
}