-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
101 lines (87 loc) · 3.23 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!groovy
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr:'10'))
skipDefaultCheckout()
}
stages {
stage("Start database") {
environment {
MYSQL_ROOT_PASSWORD = 'mypassword'
}
steps {
script {
docker.image('mysql:5.6').withRun("-e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}") { mysql_container ->
stage("Wait until DB will be accessible") {
try {
timeout(time: 120, unit: 'SECONDS') {
waitUntil {
try {
sh "docker exec ${mysql_container.id} mysql --user=root --password='${MYSQL_ROOT_PASSWORD}' -e 'SELECT 1'"
return true
} catch (exception) {
return false
}
}
}
} catch (timeout_exception) {
error "Couldn't connect to DB. See previous logs for more details."
}
}
docker.image('ruby:2.3.1').inside("--link ${mysql_container.id}:mysql") {
stage("Checkout") {
checkout scm
}
stage("Installing bundler") {
sh "gem install bundler --no-rdoc --no-ri"
}
stage("Installing dependencies") {
sh "bundle install"
sh "apt-get -qq update && apt-get -qq -y install nodejs"
}
withEnv(["DATABASE_URL=mysql2://root:${MYSQL_ROOT_PASSWORD}@mysql/films_test", "RAILS_ENV=test"]) {
stage("Preparing DB") {
sh "bundle exec rake db:create"
}
stage("Executing tests") {
sh "bundle exec rake ci:setup:rspec spec"
// Publish spec results
junit 'spec/reports/*.xml'
// Publish rcov results (requires HTML Publisher plugin)
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'coverage',
reportFiles: 'index.html',
reportName: "RCov Report"
])
}
stage("Security scan") {
sh "bundle exec brakeman -o brakeman-output.tabs --no-progress --separate-models"
// Requires Brakeman Plugin
publishBrakeman 'brakeman-output.tabs'
}
}
}
}
}
}
}
}
post {
success {
slackSend color: '#00FF00',
message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
}
failure {
emailext subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
slackSend color: '#FF0000',
message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
}
}
}