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 8
/
Copy pathJenkinsfile
58 lines (49 loc) · 2.3 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
pipeline {
agent { label 'linux-slave' }
stages {
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", 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", variable: 'NPM_TOKEN')]) {
sh "echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > $WORKSPACE/dist/.npmrc"
}
echo "publishing to npm, version: " + BUILD_VERSION
sh "npm publish"
}
}
}
}
}