-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
69 lines (64 loc) · 1.92 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
#!/usr/bin/env groovy
pipeline {
agent { label 'docker' }
environment {
// Make sure we're ignoring any override files that may be present
COMPOSE_FILE = "docker-compose.yml"
}
stages {
stage('Test') {
matrix {
agent { label 'docker' }
axes {
axis {
name 'RUBY_VERSION'
values '2.7', '3.0', '3.1', '3.2'
}
axis {
name 'LOCKFILE'
values 'activerecord-6.1', 'activerecord-7.0', 'Gemfile.lock'
}
}
stages {
stage('Build') {
steps {
// Allow postgres to initialize while the build runs
sh 'docker-compose up -d postgres'
sh "docker-compose build --pull --build-arg RUBY_VERSION=${RUBY_VERSION} --build-arg app"
sh "BUNDLE_LOCKFILE=${LOCKFILE} docker-compose run --rm app bundle exec rake db:drop db:create db:migrate"
sh "BUNDLE_LOCKFILE=${LOCKFILE} docker-compose run --rm app bundle exec rake"
}
}
}
}
}
stage('Lint') {
steps {
sh "docker-compose build --pull"
sh "docker-compose run --rm app bin/rubocop"
}
}
stage('Deploy') {
when {
allOf {
expression { GERRIT_BRANCH == "master" }
environment name: "GERRIT_EVENT_TYPE", value: "change-merged"
}
}
steps {
lock( // only one build enters the lock
resource: "${env.JOB_NAME}" // use the job name as lock resource to make the mutual exclusion only for builds from the same branch/tag
) {
withCredentials([string(credentialsId: 'rubygems-rw', variable: 'GEM_HOST_API_KEY')]) {
sh 'docker-compose run -e GEM_HOST_API_KEY --rm app /bin/bash -lc "./bin/publish.sh"'
}
}
}
}
}
post {
cleanup {
sh 'docker-compose down --remove-orphans --rmi all'
}
}
}