-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
166 lines (166 loc) · 6.91 KB
/
Copy pathJenkinsfile
File metadata and controls
166 lines (166 loc) · 6.91 KB
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
pipeline {
agent any
triggers {
// Update/build master at 9pm PT.
// cron(env.BRANCH_NAME == 'master' ? '0 23 * * *' : '')
}
environment {
TAG = "${env.BRANCH_NAME}"
TOKEN = credentials('pantheon-machine-token')
ID_RSA = credentials('pantheon-ssh-key')
// Set Git user for commits.
GIT_COMMITTER_NAME = "Drydock CI"
GIT_COMMITTER_EMAIL = "ci@drydock.cloud"
}
stages {
stage('Code linting') {
when { anyOf { branch 'master'; changeRequest(); } }
steps {
script {
// Check bash script formatting
sh 'find * -name *.sh -print0 | xargs -n1 -I "{}" -0 docker run -i -v "$(pwd)":/workdir -w /workdir unibeautify/beautysh -c "/workdir/{}"'
// Lint bash scripts using shellcheck
sh 'find * -name *.sh -print0 | xargs -n1 -I "{}" -0 docker run -i --rm -v "$PWD":/src koalaman/shellcheck "/src/{}"'
// Lint Dockerfiles using hadolint
sh 'find * -name Dockerfile* -print0 | xargs -n1 -I "{}" -0 docker run -i --rm -v "$PWD":/src hadolint/hadolint hadolint "/src/{}"'
}
}
}
// If we are building master, check out the real branch now so we can commit changes later
// Potentially could switch this to a git {} task
stage('Checkout master') {
when { branch 'master' }
steps {
script {
sh 'git fetch origin master'
sh 'git checkout master'
sh 'git reset --hard origin/master'
}
}
}
stage('Update configs') {
when { anyOf { branch 'master'; changeRequest(); } }
steps {
script {
sh 'docker build -t getconfig getconfig'
sh 'docker run --user=$(id -u) -i -v $(pwd)/php:/build-tools-ci/php -v $(pwd)/mysql:/build-tools-ci/mysql -v $(pwd)/nginx:/build-tools-ci/nginx -e TOKEN -e ID_RSA getconfig:latest dockertest'
// If we are on master and there are no changes, then pass the build early.
def result = sh 'if [[ "$(git symbolic-ref HEAD 2>/dev/null)" == "refs/heads/master" ]]; then git diff --exit-code; fi'
if (result != 0) {
echo 'No changes on master build, ending early.'
currentBuild.result = 'SUCCESS'
return
}
}
}
}
stage('Build') {
when { anyOf { branch 'master'; changeRequest(); } }
parallel {
stage('PHP 7.1') {
steps {
script {
withEnv(['VERSION=7.1']) {
// Retry the build if it fails. DNF can fail on fetching mirrors as the mirror server 503s when the list is rotated.
// See: https://bugzilla.redhat.com/show_bug.cgi?id=1593033
retry(3) {
sh 'docker build -t "drydockcloud/drupal-pantheon-php-${VERSION}:${TAG}" ./php --build-arg version="${VERSION}"'
}
}
}
}
}
stage('PHP 7.2') {
steps {
script {
withEnv(['VERSION=7.2']) {
retry(3) {
sh 'docker build -t "drydockcloud/drupal-pantheon-php-${VERSION}:${TAG}" ./php --build-arg version="${VERSION}"'
}
}
}
}
}
stage('PHP 7.3') {
steps {
script {
withEnv(['VERSION=7.3']) {
retry(3) {
sh 'docker build -t "drydockcloud/drupal-pantheon-php-${VERSION}:${TAG}" ./php --build-arg version="${VERSION}"'
}
}
}
}
}
stage('NGINX') {
steps {
script {
sh 'docker build -t "drydockcloud/drupal-pantheon-nginx:${TAG}" ./nginx'
}
}
}
stage('MySQL') {
steps {
script {
sh 'docker build -t "drydockcloud/drupal-pantheon-mysql:${TAG}" ./mysql'
}
}
}
}
}
stage('Test PHP 7.1') {
when { anyOf { branch 'master'; changeRequest(); } }
steps {
script {
withEnv(['VERSION=7.1']) {
sh 'test/test.sh'
}
}
}
}
stage('Test PHP 7.2') {
when { anyOf { branch 'master'; changeRequest(); } }
steps {
script {
withEnv(['VERSION=7.2']) {
sh 'test/test.sh'
}
}
}
}
stage('Test PHP 7.3') {
when { anyOf { branch 'master'; changeRequest(); } }
steps {
script {
withEnv(['VERSION=7.3']) {
sh 'test/test.sh'
}
}
}
}
stage('Commit and push to master') {
when { branch 'master' }
steps {
script {
sh 'git remote set-url origin git@github.com:drydockcloud/drupal-pantheon.git'
sh 'git add php nginx mysql'
try {
// If there are changes added, this will exit non-zero so we can commit them.
sh 'git diff --cached --exit-code'
}
catch (exc) {
sh 'git commit -m"Automatic update for $(date --iso-8601=date)"'
// Cut a tag for the day (if it does not already exist - otherwise just let it roll into tomorrows tag).
sh 'git tag "$(date \"+v%Y.%m.%d-0\")" || true'
sh 'rm ssh.sock || true; eval $(ssh-agent -a ssh.sock -s) && echo "$ID_RSA" | base64 -d | ssh-add - && git push origin master && git push origin --tags; ssh-add -D'
}
}
}
}
}
post {
failure {
slackSend channel: 'bowline-drydock', message: "Build failed, see build log for details: ${env.BUILD_URL}console"
}
}
}