-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
85 lines (83 loc) · 2.35 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
pipeline {
agent any // Run pipeline on any available agent
// Start pipeline stages
stages {
stage('Build docker test image') {
environment {
RAILS_ENV = 'test'
}
steps {
echo 'Building docker image..'
// build with host user id
sh 'docker-compose build \
--build-arg UID=$(id -u) \
--build-arg RAILS_ENV=${RAILS_ENV}'
}
}
stage('Rubocop') {
steps {
echo 'Running code analysis..'
sh 'docker-compose run --rm app bundle exec rubocop \
--format html \
--out rubocop/index.html \
--format fuubar'
}
}
stage('RSpec') {
steps {
echo 'Running unit tests..'
sh 'docker-compose run --rm app bundle exec rspec \
--profile 10 \
--format RspecJunitFormatter \
--out ${REPORTS_DIR}/junit/rspec.xml \
--format Fuubar'
}
}
stage('Deploy to gemstash server') {
when { branch 'master' }
environment {
GEMSTASH_URL = credentials('gemstash-url')
GEMSTASH_PUSH_KEY = credentials('gemstash-push-key')
}
steps {
echo 'Deploying....'
// build gem and deploy it to private gem server
sh 'docker-compose run \
-e GEMSTASH_URL=${GEMSTASH_URL} \
-e GEMSTASH_PUSH_KEY=${GEMSTASH_PUSH_KEY} \
--rm app ./deploy-gem.sh'
}
}
}
// Post build stages actions
post {
always {
// publish rubocop html report results
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'rubocop',
reportFiles: 'index.html',
reportName: 'Linter report',
reportTitles: 'Rubocop report'
])
// collect junit test results
junit "**/${REPORTS_DIR}/junit/*.xml"
// publish simplecov html report results
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'coverage',
reportFiles: 'index.html',
reportName: 'Code coverage report',
reportTitles: 'SimpleCov report'
])
// remove docker containers and its volumes
sh 'docker-compose down --volumes'
// clean Jenkins workspace
cleanWs()
}
}
}