This repository has been archived by the owner on May 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
112 lines (112 loc) · 3.58 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
102
103
104
105
106
107
108
109
110
111
112
pipeline {
agent {
label "docker"
}
parameters {
string(name: "BRAIN_COMMIT", defaultValue: "", description: "Force revision to this specific commit")
booleanParam(name: "SKIP_INTEGRATION", defaultValue: false, description: "Whether integration should be skipped")
string(name: "CELL_NUMBER", defaultValue: "1", description: "Integration. Number of cells to deploy")
}
stages {
stage("Retrieve build environment") {
steps {
script {
if (params.BRAIN_COMMIT) {
GIT_COMMIT = params.BRAIN_COMMIT
sh("git checkout -fb integration ${params.BRAIN_COMMIT}")
}
}
script {
GIT_COMMIT_MESSAGE = sh(returnStdout: true, script: "git rev-list --format=%B --max-count=1 ${GIT_COMMIT}").trim()
}
}
}
stage("Build image") {
steps {
script {
docker.build("smartbox/brain:${GIT_COMMIT}")
}
}
}
stage("Analyze image") {
parallel {
stage("Style analysis") {
steps {
sh("docker run --rm smartbox/brain:${GIT_COMMIT} bundle exec rubocop --no-color -D")
}
}
stage("Security analysis") {
steps {
sh("docker run --rm smartbox/brain:${GIT_COMMIT} bundle exec brakeman --no-color -zA")
}
}
stage("Model specs") {
steps {
sh("docker run --rm -e COVERAGE=models -t smartbox/brain:${GIT_COMMIT} bundle exec rspec --no-color spec/models")
}
}
stage("Request specs") {
steps {
sh("docker run --rm -e COVERAGE=requests -t smartbox/brain:${GIT_COMMIT} bundle exec rspec --no-color spec/requests")
}
}
stage("Library specs") {
steps {
sh("docker run --rm -e COVERAGE=lib -t smartbox/brain:${GIT_COMMIT} bundle exec rspec --no-color spec/lib")
}
}
stage("All specs") {
steps {
sh("docker run --rm -t smartbox/brain:${GIT_COMMIT} bundle exec rspec --no-color")
}
}
}
}
stage ("Build production image") {
steps {
script {
docker.build("smartbox/brain:${GIT_COMMIT}-production", "-f Dockerfile.production .")
}
}
}
stage ("Internal publish") {
steps {
script {
docker.withRegistry("https://registry.smartbox.io/") {
docker.image("smartbox/brain:${GIT_COMMIT}-production").push(GIT_COMMIT)
}
}
}
}
stage("Run integration tests") {
when { expression { !params.SKIP_INTEGRATION } }
steps {
script {
build job: "integration/master", parameters: [
text(name: "COMMIT_MESSAGE", value: GIT_COMMIT_MESSAGE),
string(name: "BRAIN_COMMIT", value: GIT_COMMIT),
string(name: "CELL_NUMBER", value: params.CELL_NUMBER)
]
}
}
}
stage("Publish") {
when { expression { BRANCH_NAME == "master" && !params.SKIP_INTEGRATION } }
steps {
script {
docker.withRegistry("https://registry.hub.docker.com", "docker-hub-credentials") {
docker.image("smartbox/brain:${GIT_COMMIT}-production").push("latest")
}
}
}
}
}
post {
always {
sh("docker rmi -f --no-prune smartbox/brain:${GIT_COMMIT}")
sh("docker rmi -f --no-prune smartbox/brain:${GIT_COMMIT}-production")
sh("docker rmi -f --no-prune registry.hub.docker.com/smartbox/brain:latest")
sh("docker rmi -f --no-prune registry.smartbox.io/smartbox/brain:${GIT_COMMIT}")
}
}
}