forked from gohkhoonhiang/sidekiq_adhoc_job
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
67 lines (65 loc) · 2.33 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
@Library('devops-library')
def slack_channel = "#loyalty-notifications"
def env_name = "test"
def ruby_bundler_versions = [
['2.7.8', '2.4.22'],
['3.1.5', '2.5.10']
]
pipeline {
agent any
options {
buildDiscarder(logRotator(daysToKeepStr: '60', artifactNumToKeepStr: '20'))
}
environment {
SLACK_TOKEN = credentials("PB_SLACK_TOKEN")
}
stages{
stage("Ensure unique build") {
steps {
script {
// Cancel any already running build for the same branch
def buildNumber = env.BUILD_NUMBER as int
if (buildNumber > 1) milestone(buildNumber - 1)
milestone(buildNumber)
}
}
}
stage("Test") {
environment {
BUNDLE_PATH = "/build/vendor/bundle"
REDIS_URL = "redis://redis-${env.BUILD_NUMBER}:6379/1"
}
steps {
script {
ruby_bundler_versions.each { versions ->
def ruby_version = versions[0]
def bundler_version = versions[1]
docker.image('redis').withRun() { c_redis ->
docker.image("ruby:${ruby_version}-alpine")
.inside("-u root --link ${c_redis.id}:redis-${env.BUILD_NUMBER} -v bundle_cache_gem_tests:${env.BUNDLE_PATH} -v logs_gem_tests:${env.WORKSPACE}/log") {
stage("Prepare test env (ruby ${ruby_version})") {
sh "apk --update --no-cache add build-base git libsodium-dev --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing"
sh "apk --update add dockerize --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing --allow-untrusted"
sh "gem install bundler:${bundler_version}"
sh 'bundle install --jobs=4 --retry=3'
sh "dockerize -wait tcp://redis-${env.BUILD_NUMBER}:6379 -timeout 1m"
}
stage("Run rspec (ruby ${ruby_version})") {
sh 'bundle exec rspec --format progress --format RspecJunitFormatter --out rspec.xml'
}
} // end inside
} // end docker redis
} // end ruby_bundler_versions.each
} // end script
} // end steps
} // end of test stage
} // end of stages
post {
cleanup {
pipelineCleanup()
}
always {
postPipeline(slack_channel, env_name)
}
}
}