-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
147 lines (134 loc) · 5.11 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
pipeline {
agent {
label 'worker'
}
environment {
REPO_NAME = sh(returnStdout: true, script: 'basename `git remote get-url origin` .git').trim()
LATEST_AUTHOR = sh(returnStdout: true, script: 'git show -s --pretty=%an').trim()
LATEST_COMMIT_ID = sh(returnStdout: true, script: 'git describe --tags --long --always').trim()
PATH = "${WORKSPACE}/node_modules/.bin:${env.PATH}"
}
stages {
stage ('Install') {
steps {
setup_basic_env()
script {
echo REPO_NAME
echo LATEST_AUTHOR
echo LATEST_COMMIT_ID
echo env.BRANCH_NAME
echo env.BUILD_NUMBER
echo env.TAG_NAME
}
nodejs(nodeJSInstallationName: 'NodeJS 18') {
sh 'npm install'
}
}
post {
failure {
rocket_basicsend("*${env.REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* install on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${env.LATEST_AUTHOR}. Review the code!")
}
}
}
stage ('Test') {
steps {
nodejs(nodeJSInstallationName: 'NodeJS 18') {
sh 'ng test --karma-config karma-jenkins.conf.js --code-coverage'
}
}
post {
failure {
rocket_testfail()
}
}
}
stage ('Reports and Statistics') {
steps {
script {
def scannerHome = tool 'SonarScanner 4';
withSonarQubeEnv('sonarcloud GIScience/ohsome') {
if (env.CHANGE_ID) {
SONAR_CLI_PARAMETER = " " +
"-Dsonar.pullrequest.key=${env.CHANGE_ID} " +
"-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} " +
"-Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
} else {
SONAR_CLI_PARAMETER = " " +
"-Dsonar.branch.name=${env.BRANCH_NAME}"
}
nodejs('NodeJS 18') {
sh "${scannerHome}/bin/sonar-scanner " + SONAR_CLI_PARAMETER
}
}
}
}
post {
failure {
rocket_reportfail()
}
}
}
stage ('Build and Deploy INT') {
when {
expression {
return (env.BRANCH_NAME == 'main' && env.TAG_NAME == null )
}
}
steps {
// TODO fix and replace deployment
nodejs(nodeJSInstallationName: 'NodeJS 18') {
sh 'npm run build:int'
}
withCredentials([gitUsernamePassword(credentialsId: 'e78912d9-de2f-473c-a1b2-6a2ee82a879a')]) {
sh 'git config --global user.email "nobody@example.org"' // TODO remove
sh 'git config --global user.name "Jenkins"' // TODO remove
sh 'rm -rf /tmp/tmp-stats-frontend-git'
sh 'git clone https://gitlab.gistools.geog.uni-heidelberg.de/giscience/big-data/ohsome/ohsome-now/deployments/stats-frontend.git /tmp/tmp-stats-frontend-git'
sh 'rm -r /tmp/tmp-stats-frontend-git/*'
sh 'cp -r dist/* /tmp/tmp-stats-frontend-git/'
sh "cd /tmp/tmp-stats-frontend-git/ && git add . && git commit -m 'deploy ${LATEST_COMMIT_ID}' --allow-empty && git push"
}
echo 'Please redeploy the deployment git manually (for now)!' // TODO replace
}
post {
failure {
rocket_basicsend("*${env.REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* build and deploy INT stage on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${env.LATEST_AUTHOR}. Review the code!")
}
}
}
stage ('Build and Deploy PROD') {
when {
expression {
return (env.BRANCH_NAME != 'main' && env.TAG_NAME)
}
}
steps {
// TODO fix and replace deployment
nodejs(nodeJSInstallationName: 'NodeJS 18') {
sh 'npm run build:prod'
}
withCredentials([gitUsernamePassword(credentialsId: 'e78912d9-de2f-473c-a1b2-6a2ee82a879a')]) {
sh 'git config --global user.email "nobody@example.org"' // TODO remove
sh 'git config --global user.name "Jenkins"' // TODO remove
sh 'rm -rf /tmp/tmp-stats-frontend-git'
sh 'git clone https://gitlab.gistools.geog.uni-heidelberg.de/giscience/big-data/ohsome/ohsome-now/deployments/stats-frontend.git /tmp/tmp-stats-frontend-git'
sh 'rm -r /tmp/tmp-stats-frontend-git/*'
sh 'cp -r dist/* /tmp/tmp-stats-frontend-git/'
sh "cd /tmp/tmp-stats-frontend-git/ && git add . && git commit -m 'deploy ${LATEST_COMMIT_ID}' --allow-empty && git tag ${env.TAG_NAME} && git push && git push --tags"
}
echo 'Please redeploy the deployment git manually (for now)!' // TODO replace
}
post {
failure {
rocket_basicsend("*${env.REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* build and deploy PROD stage on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${env.LATEST_AUTHOR}. Review the code!")
}
}
}
stage('Wrapping up') {
steps {
encourage()
status_change()
}
}
}
}