forked from moltin/js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
110 lines (94 loc) · 2.82 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
def err = null
try {
node {
stage ("Checkout") {
gitClean()
checkout scm
}
stage ("Provisioning") {
docker.image('node:alpine').inside {
sh "npm install"
}
}
stage ("Run tests") {
docker.image('node:alpine').inside {
sh "npm run-script test"
}
}
if (env.BRANCH_NAME == 'master') {
sshagent (credentials: ['github-moltin-moltinbot-ssh-key']) {
stage ("Checkout master branch") {
gitClean()
sh "git checkout master"
sh "git pull"
}
}
stage ("Prune + Provisioning") {
docker.image('node:alpine').inside {
sh "npm prune"
}
}
stage ("Provisioning") {
docker.image('node:alpine').inside {
sh "npm install"
}
}
stage ("Configure npm") {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'npm-moltin-moltinbot-password', usernameVariable: 'NPM_USERNAME', passwordVariable: 'NPM_PASSWORD']]) {
sh "docker run -e NPM_USER=$NPM_USERNAME -e NPM_PASS=\"$NPM_PASSWORD\" -e NPM_EMAIL=$NPM_EMAIL bravissimolabs/generate-npm-authtoken > .npmrc.tmp"
env.NPM_TOKEN = sh (
script: "set +x ; echo -n \$(cat .npmrc.tmp) | sed -n -e 's/^.*_authToken=//p'",
returnStdout: true
)
}
}
try {
stage ("Versioning") {
withCredentials([[$class: 'StringBinding', credentialsId: 'github-moltin-moltinbot-token', variable: 'GH_TOKEN']]) {
sshagent (credentials: ['github-moltin-moltinbot-ssh-key']) {
env.CI=true
env.GIT_BRANCH="origin/master"
docker.image("zot24/semantic-release").inside {
sh "semantic-release pre"
}
docker.image('node:alpine').inside {
sh "mv .npmrc.tmp .npmrc"
sh "npm publish"
}
docker.image("zot24/semantic-release").inside {
sh "semantic-release post"
}
}
}
}
stage ("Cleaning up") {
sh "rm .npmrc"
}
} catch (Exception e) {
sh "rm .npmrc.tmp"
echo "Failed versioning with semantic-release, check logs above)"
}
}
}
currentBuild.result = "SUCCESS"
} catch (caughtError) {
err = caughtError
currentBuild.result = "FAILURE"
} finally {
echo "RESULT: ${currentBuild.result}"
if (err) {
slackSend color: "danger",
message:
""":cold_sweat: Something went wrong!.
|${env.BUILD_URL}
|Branch: ${env.BRANCH_NAME}""".stripMargin()
throw err
} else {
slackSend color: "good",
message:
""":smirk: All good!.
|${env.BUILD_URL}
|Branch: ${env.BRANCH_NAME}""".stripMargin()
}
}