-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
113 lines (98 loc) · 3.27 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
113
#!groovy
def packageVersion = "undefined"
def deployUserAndHost = "${params.deployUserAndHost}"
def deployBaseDirectory = "${params.deployBaseDirectory}"
def buildNode = "${params.buildNode}"
pipeline {
agent {
node {
label "${buildNode}"
}
}
tools {
nodejs 'nodejs-18'
}
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '3'))
}
stages {
stage('Configure http proxy') {
when { expression { env.HTTP_PROXY != '' } }
steps {
sh "npm config set proxy ${env.HTTP_PROXY}"
}
}
stage('Configure https proxy') {
when { expression { env.HTTPS_PROXY != '' } }
steps {
sh "npm config set https-proxy ${env.HTTPS_PROXY}"
}
}
stage('Install') {
steps {
sh "env"
sh "npm --version"
sh "node --version"
sh "rm --recursive --force node_modules"
sh "npm install"
}
}
stage('Build') {
steps {
sh "npm run build"
}
}
stage('Test') {
steps {
sh "docker stop docker_chromium_1 || true && docker rm docker_chromium_1 || true"
sh "npm test || echo \"Some or all tests failed\""
}
}
stage('Determine version from package.json') {
steps {
script {
packageVersion = sh(returnStdout: true, script: 'jq --raw-output .version package.json').trim()
}
}
}
stage('Require unique deploy directory') {
when { environment name: 'BRANCH_NAME', value: 'main' }
steps {
sh "ssh ${deployUserAndHost} \"if [ -d ${deployBaseDirectory}/${packageVersion} ]; then echo deploy directory already exists; exit 1; fi\""
}
}
stage('Deploy') {
steps {
sh "chmod --verbose --recursive u+r+w+X,g+r-w+X,o-r-w-x dist/"
sh "ssh ${deployUserAndHost} \"mkdir --parents --mode=750 ${deployBaseDirectory}/${packageVersion}\""
sh "scp -rp dist/* ${deployUserAndHost}:${deployBaseDirectory}/${packageVersion}/"
}
}
stage('Publish package to npmjs.com') {
when { environment name: 'BRANCH_NAME', value: 'main' }
environment {
NPM_TOKEN = credentials('npm-token')
}
steps {
sh 'echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > .npmrc'
sh 'npm publish'
sh 'rm .npmrc'
}
}
}
post {
success {
slackSend(message: "Success ${env.JOB_NAME} ${packageVersion} (<${env.BUILD_URL}|Open>)")
}
unstable {
slackSend(message: "Unstable ${env.JOB_NAME} ${packageVersion} (<${env.BUILD_URL}|Open>)")
}
failure {
slackSend(message: "Failure ${env.JOB_NAME} ${packageVersion} (<${env.BUILD_URL}|Open>)")
}
changed {
slackSend(message: "Changed ${env.JOB_NAME} ${packageVersion} (<${env.BUILD_URL}|Open>)")
}
}
}