-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile
More file actions
133 lines (124 loc) · 3.89 KB
/
Copy pathJenkinsfile
File metadata and controls
133 lines (124 loc) · 3.89 KB
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
pipeline {
agent {
label 'xlarge'
}
options {
timeout(time: 30, unit: 'MINUTES')
}
environment {
// this variable defines which branches will be deployed
SNAPSHOT_BRANCH_REGEX = /(^main$)/
RELEASE_REGEX = /^v?([0-9]+(\.[0-9]+)*)(-(RC|rc|beta|alpha)\.[0-9]+)?$/
REPO_NAME = sh(returnStdout: true, script: 'basename `git remote get-url origin` .git').trim()
VERSION = sh(returnStdout: true, script: 'grep -Po "\\"version\\": \\"\\K([^\\"]+)" package.json').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()
DOCKER_IMAGE_NAME = 'repo.heigit.org/heigit/ohsome-dashboard'
DOCKER_CREDENTIALS_ID = 'docker-heigit-ci-service'
DOCKER_REGISTRY_URL = 'https://repo.heigit.org'
PATH = "${WORKSPACE}/node_modules/.bin:${env.PATH}"
}
stages {
stage ('Install') {
steps {
script {
echo REPO_NAME
echo LATEST_AUTHOR
echo LATEST_COMMIT_ID
echo env.BRANCH_NAME
echo env.BUILD_NUMBER
echo env.TAG_NAME
}
nodejs('NodeJS 24') {
sh 'npm clean-install'
}
}
post {
failure {
basicsend("*${REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* to install packages, check your packages.json file (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${LATEST_AUTHOR}.")
}
}
}
stage ('Build') {
steps {
nodejs('NodeJS 24') {
sh 'npm run build:prod'
}
}
post {
failure {
rocket_buildfail()
}
}
}
stage ('Test') {
steps {
nodejs('NodeJS 24') {
sh 'npm run test:ci'
}
}
post {
failure {
rocket_testfail()
}
}
}
stage ('Reports and Statistics') {
steps {
script {
def scannerHome = tool 'SonarScanner 4';
withSonarQubeEnv('sonarcloud GIScience/ohsome') {
SONAR_CLI_PARAMETER = "-Dsonar.projectVersion=${VERSION} "
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 24') {
sh "${scannerHome}/bin/sonar-scanner " + SONAR_CLI_PARAMETER
}
}
}
}
post {
failure {
rocket_reportfail()
}
}
}
stage('Build and publish Docker image') {
steps {
script {
docker.withRegistry(DOCKER_REGISTRY_URL, DOCKER_CREDENTIALS_ID) {
if (env.BRANCH_NAME ==~ SNAPSHOT_BRANCH_REGEX) {
dockerImage = docker.build(DOCKER_IMAGE_NAME + ':' + env.BRANCH_NAME, '--build-arg build_config=test .')
grypeScan(scanDest: 'docker:' + dockerImage.id, repName: 'myGrypeScanResult.txt', autoInstall: true)
dockerImage.push()
}
if (VERSION ==~ RELEASE_REGEX && env.TAG_NAME ==~ RELEASE_REGEX) {
dockerImage = docker.build(DOCKER_IMAGE_NAME + ':' + VERSION, '--build-arg build_config=prod .')
grypeScan(scanDest: 'docker:' + dockerImage.id, repName: 'myGrypeScanResult.txt', autoInstall: true)
dockerImage.push()
dockerImage.push('latest')
}
}
recordIssues enabledForFailure: true, tools: [grype()]
}
}
post {
failure {
rocket_buildfail()
}
}
}
stage('Wrapping Up') {
steps {
encourage()
status_change()
}
}
}
}