forked from HadoukenIO/fdc3-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
62 lines (57 loc) · 2.68 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
pipeline {
agent { label 'linux-slave' }
stages {
stage ('test'){
steps {
sh "npm i"
sh "npm run check"
sh "npm test"
}
}
stage ('build') {
when { branch "develop" }
steps {
script {
GIT_SHORT_SHA = sh ( script: "git rev-parse --short HEAD", returnStdout: true ).trim()
VERSION = sh ( script: "node -pe \"require('./package.json').version\"", returnStdout: true ).trim()
PREREL_VERSION = VERSION + "-alpha." + env.BUILD_NUMBER
S3_LOC = env.DSERVICE_S3_ROOT + "fdc3/" + GIT_SHORT_SHA
STAGING_JSON = env.DSERVICE_S3_ROOT + "fdc3/" + "app.staging.json"
}
sh "npm i"
sh "GIT_SHORT_SHA=${GIT_SHORT_SHA} npm run build"
sh "echo ${GIT_SHORT_SHA} > ./build/SHA.txt"
sh "aws s3 cp ./build ${S3_LOC}/ --recursive"
sh "aws s3 cp ./build/app.json ${STAGING_JSON}"
echo "publishing pre-release version to npm: " + PREREL_VERSION
withCredentials([string(credentialsId: "NPM_TOKEN_WRITE", variable: 'NPM_TOKEN')]) {
sh "echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > $WORKSPACE/.npmrc"
}
sh "npm version --no-git-tag-version " + PREREL_VERSION
sh "npm publish --tag alpha"
sh "npm version --no-git-tag-version " + VERSION
}
}
stage ('build-prod') {
when { branch "master" }
steps {
script {
GIT_SHORT_SHA = sh ( script: "git rev-parse --short HEAD", returnStdout: true ).trim()
VERSION = sh ( script: "node -pe \"require('./package.json').version\"", returnStdout: true ).trim()
S3_LOC = env.DSERVICE_S3_ROOT + "fdc3/" + GIT_SHORT_SHA
PROD_JSON = env.DSERVICE_S3_ROOT + "fdc3/" + "app-" + VERSION + ".json"
}
sh "npm i"
sh "GIT_SHORT_SHA=${GIT_SHORT_SHA} npm run build"
sh "echo ${GIT_SHORT_SHA} > ./build/SHA.txt"
sh "aws s3 cp ./build ${S3_LOC}/ --recursive"
sh "aws s3 cp ./build/app.json ${PROD_JSON}"
echo "publishing to npm, version: " + VERSION
withCredentials([string(credentialsId: "NPM_TOKEN_WRITE", variable: 'NPM_TOKEN')]) {
sh "echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > $WORKSPACE/.npmrc"
}
sh "npm publish"
}
}
}
}