This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
forked from BitSaber/incy-io-kiosk-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
120 lines (120 loc) · 4.59 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
113
114
115
116
117
118
119
120
pipeline {
agent {
label 'dind'
}
environment {
NODEJS_HOME = '/opt/tools/nodejs/node-v11.4.0-linux-x64'
PATH = "/opt/tools/yarn/yarn-v1.12.3/bin:/opt/tools/nodejs/node-v11.4.0-linux-x64/bin:$PATH"
}
stages {
stage('Install Dependencies') {
steps {
sh 'yarn install'
}
}
stage('Run tests') {
steps {
sh 'yarn test'
}
}
stage('Static code analysis') {
steps {
withCredentials([string(credentialsId: 'jenkins-slaves-sonar-token', variable: 'SONAR_AUTH_TOKEN')]) {
withSonarQubeEnv('BitSaber Sonar') {
script {
scannerHome = tool 'SonarScanner'
}
sh "${scannerHome}/bin/sonar-scanner -D sonar.login=\"${SONAR_AUTH_TOKEN}\""
}
}
}
}
stage("Quality Gate") {
steps {
timeout(time: 10, unit: 'MINUTES') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
// Requires SonarQube Scanner for Jenkins 2.7+
waitForQualityGate abortPipeline: true
}
}
}
stage('Linter') {
steps {
sh 'yarn lint'
}
}
stage('Build Project') {
steps {
sh 'yarn build'
}
}
stage('Deploy to local test') {
steps {
script {
lowercaseBranch = env.BRANCH_NAME.toLowerCase()
}
withCredentials([file(credentialsId: '2d6f0282-6e9d-4885-b209-3a8baf6cb797', variable: 'IDRSA')]) {
sh 'cp "$IDRSA" ~/.ssh/id_rsa'
sh 'chown $(whoami): ~/.ssh/id_rsa'
sh 'chmod 600 ~/.ssh/id_rsa'
sh 'ssh-keyscan bitsaber.net > ~/.ssh/known_hosts'
sh "lftp -e \"rm -r -f ${lowercaseBranch}; mkdir ${lowercaseBranch}; mirror -R dist/ ${lowercaseBranch}/; quit;\" -u jenkins-dev-deploy, sftp://bitsaber.net/branches"
}
}
}
stage('Robot Tests') {
environment {
PATH = "$PATH:/opt/chromedriver/"
}
steps {
sh 'cp -r dist heroku_docker/app'
sh 'docker build --tag incy-io-kiosk-frontend .'
sh 'docker run -d --name incy-io-kiosk-frontend -p 3000:3000 incy-io-kiosk-frontend'
sh 'robot -d robot_reports __tests__/robot'
sh 'docker stop incy-io-kiosk-frontend'
step([
$class : 'RobotPublisher',
outputPath: "./robot_reports/",
outputFileName : "output.xml",
disableArchiveOutput : false,
reportFileName: "report.html",
logFileName: "log.html",
passThreshold : 100,
unstableThreshold: 95.0,
otherFiles : "*.png"
])
}
}
stage('Deploy to staging') {
when {
expression { return env.BRANCH_NAME == 'develop' }
}
steps {
withCredentials([file(credentialsId: '770b87fe-7835-4a6d-a769-2a7879c12b76', variable: 'HEROKUCREDS')]) {
sh 'cp "$HEROKUCREDS" ~/.netrc'
sh 'cd heroku_docker'
sh 'heroku container:login'
sh 'docker build .'
sh 'heroku container:push web --app incy-io-kiosk-staging'
sh 'heroku container:release web --app incy-io-kiosk-staging'
}
}
}
stage('Deploy to production') {
when {
expression { return env.BRANCH_NAME == 'master' }
}
steps {
withCredentials([file(credentialsId: '770b87fe-7835-4a6d-a769-2a7879c12b76', variable: 'HEROKUCREDS')]) {
sh 'cp "$HEROKUCREDS" ~/.netrc'
sh 'cd heroku_docker'
sh 'heroku container:login'
sh 'docker build .'
sh 'heroku container:push web --app incy-io-kiosk-production'
sh 'heroku container:release web --app incy-io-kiosk-production'
}
}
}
}
}