-
Notifications
You must be signed in to change notification settings - Fork 27
/
Jenkinsfile
141 lines (124 loc) · 4.46 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
@Library('jenkins-pipeline-library') import com.gentics.*
JobContext.set(this)
pipeline {
agent {
kubernetes {
label env.BUILD_TAG.take(63)
defaultContainer 'build'
yamlFile '.jenkins/pod.yaml'
}
}
parameters {
booleanParam(name: 'unittest', defaultValue: true, description: "Run unit tests")
booleanParam(name: 'e2etest', defaultValue: true, description: "Run e2e tests with testcafe")
choice(name: 'release', choices: ['none', 'patch', 'minor', 'major'], description: "Release the UI")
}
options {
withCredentials([
usernamePassword(credentialsId: 'repo.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),
usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass'),
string(credentialsId: 'sonarcube.key', variable: 'SONARCUBE_TOKEN'),
string(credentialsId: 'sonarcloud.key', variable: 'SONARCLOUD_TOKEN')
])
timestamps()
timeout(time: 1, unit: 'HOURS')
gitLabConnection('git.gentics.com')
gitlabBuilds(builds: ['Jenkins build'])
ansiColor('xterm')
}
environment {
DOCKER_TAG = "${env.GIT_BRANCH}"
GITLAB_WEBHOOK_SECRETTOKEN = credentials('gitlab-webhook-secrettoken')
}
triggers {
gitlab(
triggerOnPush: true,
triggerOnMergeRequest: true,
triggerOpenMergeRequestOnPush: 'source',
triggerOnNoteRequest: true,
noteRegex: 'Jenkins please retry a build',
ciSkip: true,
skipWorkInProgressMergeRequest: true,
addNoteOnMergeRequest: true,
setBuildDescription: true,
branchFilterType: 'All',
secretToken: env.GITLAB_WEBHOOK_SECRETTOKEN)
}
stages {
stage("Install dependencies") {
steps {
script {
githubBuildStarted()
sh "npm ci"
}
}
}
stage("Build") {
steps {
script {
sh "npm run build"
}
}
}
stage("Test") {
parallel {
stage("Unit Test") {
when {
expression {
return params.unittest
}
}
steps {
script {
sh "npm run test-ci"
}
}
}
stage("e2e Test") {
when {
expression {
return params.e2etest
}
}
steps {
sh "npm run mesh-ci && npm run e2e-ci"
}
}
}
}
stage("Deploy") {
when {
expression {
return params.release != null && params.release != 'none'
}
}
steps {
script {
sh "npm --no-git-tag-version version ${params.release}"
def buildVars = readJSON file: 'package.json'
sh "./mvnw -B versions:set -DgenerateBackupPoms=false -DnewVersion=" + buildVars.version
sshagent(["git"]) {
GitHelper.addCommit('pom.xml package.json package-lock.json', 'Release version ' + buildVars.version)
GitHelper.addTag(buildVars.version, "Release of version " + buildVars.version)
withCredentials([usernamePassword(credentialsId: 'repo.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')]) {
sh "./mvnw --settings /etc/maven-settings.xml -B deploy"
}
GitHelper.pushBranch(GitHelper.fetchCurrentBranchName())
GitHelper.pushTag(buildVars.version)
}
}
}
}
}
post {
always {
script {
githubBuildEnded()
if (params.unittest || params.e2etest) {
junit(testResults: "reports/**/*.xml")
}
}
notifyMattermostUsers()
}
}
}