-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
113 lines (104 loc) · 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
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
111
112
#!groovy
@Library('scruffy-pipeline-library@master')_
node {
// Setup
// Checkout
// Tests
// Build packages
// Push packages
// Cleanup
// Universal Defs
def environment
def version_date
def version_full
def npm_tag
// Set Up Environment Based on branch name
stage('Set Up') {
try {
version_date = new Date().format('YYYY.MMdd.HHmm')
env.CODEARTIFACT_AUTH_TOKEN = sh(script: 'aws codeartifact get-authorization-token --domain dn --query authorizationToken --output text', returnStdout: true)
switch(env.BRANCH_NAME) {
case 'main':
environment = 'production'
npm_tag = 'latest'
version_full = version_date
break
case ~/staging-test-.*/:
case ~/release-.*/:
case ~/hotfix-.*/:
environment = 'staging'
npm_tag = 'staging'
version_full = "${version_date}-${npm_tag}"
break
default:
environment = 'development'
npm_tag = 'development'
version_full = "${version_date}-${npm_tag}"
break
}
} catch (e) {
echo "Failed while setting the environment"
throw e
}
}
// Checkout package
stage('Checkout') {
try {
sh 'mkdir -p package'
dir("${env.WORKSPACE}/package") {
checkout scm
}
} catch (e) {
echo "Failed while cloning the repo"
throw e
}
}
// Restore package
stage('Restore') {
echo "Restoring package Version: ${version_full}"
try {
dir("${env.WORKSPACE}/package") {
sh 'npm install'
}
} catch (e) {
echo "Unable to restore package dependencies"
throw e
}
}
// Testing package
stage('Testing') {
echo "Testing package Version: ${version_full}"
try {
dir("${env.WORKSPACE}/package") {
sh 'npm run test'
}
} catch (e) {
echo "Testing package(s) failed"
throw e
}
}
// Publishing package
stage('Publish') {
echo "Publishing package Version: ${version_full}"
try {
dir("${env.WORKSPACE}/package") {
// rename the .npmrc file
sh "mv npmrc.package .npmrc"
sh "npm version ${version_full} --no-git-tag-version"
sh "npm publish --tag ${npm_tag}"
}
} catch (e) {
echo "Publishing package(s) failed"
throw e
}
}
// Cleanup
stage('Janitorial') {
try {
sh 'rm -Rf package'
} catch (e) {
echo "Error cleaning up the Jenkins workspace"
throw e
}
}
}