This repository has been archived by the owner on Jun 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
76 lines (66 loc) · 2.87 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
pipeline {
agent { label 'linux-slave' }
stages {
stage('Test') {
parallel {
stage('Unit Tests') {
agent { label 'linux-slave' }
steps {
sh "npm install"
sh "npm run test:unit -- --noColor -x \"--no-cache --verbose\""
sh "npm run check"
}
post {
always {
junit "dist/test/results-unit.xml"
}
}
}
}
}
stage('Build & Deploy (Staging)') {
agent { label 'linux-slave' }
when { branch "develop" }
steps {
script {
GIT_SHORT_SHA = sh ( script: "git rev-parse --short HEAD", returnStdout: true ).trim()
PKG_VERSION = sh ( script: "node -pe \"require('./package.json').version\"", returnStdout: true ).trim()
BUILD_VERSION = PKG_VERSION + "-alpha." + env.BUILD_NUMBER
}
sh "npm i"
sh "npm run build"
sh "echo ${GIT_SHORT_SHA} > ./dist/SHA.txt"
dir('./dist'){
withCredentials([string(credentialsId: "NPM_TOKEN_WRITE_2", variable: 'NPM_TOKEN')]) {
sh "echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > $WORKSPACE/dist/.npmrc"
}
echo "publishing pre-release version to npm: " + BUILD_VERSION
sh "npm version --no-git-tag-version " + BUILD_VERSION
sh "npm publish --tag alpha"
sh "npm version --no-git-tag-version " + PKG_VERSION
}
}
}
stage('Build & Deploy (Production)') {
agent { label 'linux-slave' }
when { branch "master" }
steps {
script {
GIT_SHORT_SHA = sh ( script: "git rev-parse --short HEAD", returnStdout: true ).trim()
PKG_VERSION = sh ( script: "node -pe \"require('./package.json').version\"", returnStdout: true ).trim()
BUILD_VERSION = PKG_VERSION
}
sh "npm i"
sh "npm run build"
sh "echo ${GIT_SHORT_SHA} > ./dist/SHA.txt"
dir('./dist') {
withCredentials([string(credentialsId: "NPM_TOKEN_WRITE_2", variable: 'NPM_TOKEN')]) {
sh "echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > $WORKSPACE/dist/.npmrc"
}
echo "publishing to npm, version: " + BUILD_VERSION
sh "npm publish"
}
}
}
}
}