-
Notifications
You must be signed in to change notification settings - Fork 39
/
Jenkinsfile
103 lines (96 loc) · 3.3 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
#! /usr/bin/env groovy
pipeline {
agent { label 'docker' }
environment {
COMPOSE_PROJECT_NAME = "${env.JOB_NAME}-${env.BUILD_ID}".replaceAll("/", "-").replaceAll(" ", "").toLowerCase()
COMPOSE_FILE = "docker-compose.yml:docker-compose.test.yml"
RAILS_ENV = "test"
DOCKER_REF = "${(env.GERRIT_EVENT_TYPE == 'change-merged') ? env.GERRIT_BRANCH : env.GERRIT_REFSPEC}"
DOCKER_TAG = env.DOCKER_REF.replace("refs/changes/", "").replaceAll("/", ".")
DEV_BUILD = "true"
}
stages {
stage('Build') {
steps {
sh 'docker compose build --pull'
sh 'docker compose up -d db'
}
}
stage('Prepare') {
steps {
sh 'docker compose run --rm web bundle exec rake db:migrate:reset'
}
}
stage('Test') {
stages {
stage('RSpec') {
steps {
sh 'docker compose run --name=$COMPOSE_PROJECT_NAME-rspec -e ENABLE_COVERAGE=true web bundle exec rake spec'
}
post {
always {
script {
// Build-specific coverage
sh 'docker cp $COMPOSE_PROJECT_NAME-rspec:/usr/src/app/coverage coverage'
archiveArtifacts 'coverage/**'
publishHTML target: [
allowMissing : false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : 'coverage',
reportFiles : 'index.html',
reportName : 'API Coverage Report'
]
// publish coverage to code-coverage.inseng.net/rollcall/coverage
uploadCoverage([
uploadSource: '/coverage',
uploadDest : 'rollcall/coverage'
])
}
}
}
}
stage('Test coverage') {
steps {
sh 'docker stop $COMPOSE_PROJECT_NAME-rspec'
}
}
stage('Jasmine') {
steps {
sh 'docker compose run --rm -T --name=$COMPOSE_PROJECT_NAME-jasmine web bundle exec rake spec:javascript'
}
}
stage('Brakeman') {
steps {
sh 'docker compose run --rm -T --name=$COMPOSE_PROJECT_NAME-brakeman web bundle exec brakeman'
}
}
stage('Cucumber') {
steps {
sh 'docker compose run --rm -T --name=$COMPOSE_PROJECT_NAME-cucumber web bash bin/cucumber'
}
}
stage('Synk') {
when { environment name: "GERRIT_EVENT_TYPE", value: "change-merged"}
steps {
withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) {
sh 'docker pull snyk/snyk-cli:rubygems'
sh 'docker run --rm -v "$(pwd):/project" -e SNYK_TOKEN snyk/snyk-cli:rubygems monitor --project-name=rollcall-attendance:ruby'
}
}
}
stage('Docker Image') {
steps {
sh 'docker build -t $DOCKER_REGISTRY_FQDN/jenkins/rollcall:$DOCKER_TAG .'
sh 'docker push $DOCKER_REGISTRY_FQDN/jenkins/rollcall:$DOCKER_TAG'
}
}
}
}
}
post {
cleanup {
sh 'docker compose down -v --remove-orphans --rmi all'
}
}
}