-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
93 lines (76 loc) · 2.13 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
// The GIT repository for this pipeline lib is defined in the global Jenkins setting
@Library('jenkins-pipeline-library')
import com.gentics.*
// Make the helpers aware of this jobs environment
JobContext.set(this)
final def sshAgent = '601b6ce9-37f7-439a-ac0b-8e368947d98d'
final def mattermostChannel = "#jenkins"
GenericHelper.setParameterDefinitions([
new ChoiceParameterDefinition('release', ['no', 'major', 'minor', 'patch', 'custom'] as String[], "If set to anything other than \"no\"," +
"will perform a release build including GIT push and deploy to Artifactory"),
new StringParameterDefinition('customVersion', null, "Optional: Define a custom version to release"),
])
String version = null
pipeline {
agent {
label 'dockerSlave'
}
stages {
stage('Checkout') {
steps {
sh "rm -rf *"
checkout scm
}
}
stage('Build') {
steps {
script {
// Increase the package version
if (!params.release.equals('no')) {
if (params.release.equals('custom')) {
version = params.customVersion
} else {
version = params.release
}
// Increase / read the version and remove the first letter 'v'
version = sh(script: 'npm version ' + version + ' --message "Release version %s"',
returnStdout: true).trim().substring(1)
currentBuild.description = 'Release ' + version
}
}
sshagent([sshAgent]) {
sh 'npm install'
sh 'npm run build'
}
}
}
stage('Release') {
when {
expression {
return !''.equals(params.release) && !params.release.equals('no')
}
}
steps {
echo 'Releasing version ' + version
withCredentials([string(credentialsId: 'npm-token', variable: 'NPM_TOKEN')]) {
sh 'npm config set //registry.npmjs.org/:_authToken ' + env.NPM_TOKEN
sh 'npm publish'
}
// GIT push
sshagent([sshAgent]) {
sh 'git push --follow-tags origin ' + GitHelper.fetchCurrentBranchName()
}
}
}
}
post {
always {
// Cleanup
step([$class: 'WsCleanup'])
script {
// Notify
MattermostHelper.sendStatusNotificationMessage(mattermostChannel)
}
}
}
}