forked from bambora/swaggerlicious
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
110 lines (91 loc) · 2.95 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
#!groovy
SERVICE = "swaggerlicious"
SLACK_CHANNEL = "#aal-bambora-online-ci"
def utils = new com.bambora.jenkins.pipeline.Utils()
def getGitTag() {
def tag = sh script: "git describe --exact-match --tags \$(git log -n1 --pretty='%h')", returnStdout: true
return tag.trim()
}
def getIntermediateGitTag() {
def tag = sh script: "git describe --tags", returnStdout: true
return tag.trim()
}
def slack(String msg, String channel = "", String color = null) {
withCredentials([
[
$class: "UsernamePasswordMultiBinding",
credentialsId: "aal-bambora-online-ci",
usernameVariable: "USERNAME",
passwordVariable: "PASSWORD"
]
]) {
slackSend message: msg, color: color, token: "${env.PASSWORD}", channel: channel
}
}
def notify_start(message) {
slack("*${SERVICE} (${env.BRANCH_NAME}):* ${message}", SLACK_CHANNEL, "info")
}
def notify_success(message) {
slack("*${SERVICE} (${env.BRANCH_NAME}):* ${message}", SLACK_CHANNEL, "good")
}
def notify_failure(message) {
slack("*${SERVICE} (${env.BRANCH_NAME}):* ${message}", SLACK_CHANNEL, "danger")
}
node("docker-concurrent") {
checkout scm
withCredentials([[
$class: "UsernamePasswordMultiBinding",
credentialsId: "5811c22b-8ff3-4f49-9ba5-6d6ebbffc4a5",
usernameVariable: "GIT_USERNAME",
passwordVariable: "GIT_PASSWORD"
]]) {
sh "git fetch --tags -q https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/bambora/swaggerlicious.git"
}
try {
gitTag = getGitTag()
hasGitTag = true
} catch(error) {
gitTag = getIntermediateGitTag()
hasGitTag = false
}
stage("Build") {
notify_start("Building of ${gitTag} has started...")
try {
docker.image("node:7.0").inside("-u 0:0") {
sh "npm install"
env.NODE_ENV = "production"
sh "npm run build:production"
}
} catch (error) {
notify_failure("Building of ${gitTag} failed!")
throw error
}
notify_success("Building of ${gitTag} was successful.")
}
stage("Publish to public NPM") {
if (!(env.BRANCH_NAME == "master" && hasGitTag)) {
echo "Nothing to publish"
return
}
notify_start("Publishing ${gitTag} to the public NPM repository...")
try {
withCredentials([[
$class: "StringBinding",
credentialsId: "public-npm-repository",
variable: "NPM_AUTH_TOKEN"
]]) {
docker.image("node:7.0").inside("-u 0:0") {
sh "echo '//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN' > .npmrc"
sh "npm publish --access public"
}
}
} catch (error) {
notify_failure("Publishing of ${gitTag} to the public NPM repository failed!")
throw error
}
def version = gitTag.substring(1)
notify_success("""Publishing of ${gitTag} to the public NPM repository was successful.\n
Direct link: https://registry.npmjs.org/@bambora/swaggerlicious/-/swaggerlicious-${version}.tgz
NPM install: `npm install @bambora/swaggerlicious@${version}`.""")
}
}