-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathJenkinsfile
More file actions
86 lines (75 loc) · 2.96 KB
/
Jenkinsfile
File metadata and controls
86 lines (75 loc) · 2.96 KB
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
#!groovy
pipeline {
agent any
stages {
stage('Run unit tests') {
agent {
label 'master'
}
steps {
sh 'docker run --rm -w `pwd` -v `pwd`:`pwd` node:18.13.0 npm install --force'
sh 'docker run --rm -w `pwd` -v `pwd`:`pwd` node:18.13.0 npm test'
junit 'test-results.xml'
}
}
stage('Sonar') {
agent {
label 'master'
}
steps {
script {
String scannerHome = tool name: 'sonar-next', type: 'hudson.plugins.sonar.SonarRunnerInstallation';
withSonarQubeEnv('sonar-next') {
sh "${scannerHome}/bin/sonar-scanner \
-Dsonar.sources=api \
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info \
-Dsonar.projectKey=\"smartling-api-sdk-nodejs\" \
-Dsonar.projectName=\"API SDK nodejs\" \
-Dsonar.projectVersion=${env.BUILD_NUMBER}"
}
}
}
}
stage("Quality Gate") {
steps {
script {
try {
timeout(time: 5, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure"
}
}
}
catch (err) {
// Catch timeout exception but not Quality Gate.
String errorString = err.getMessage();
if (errorString == "Pipeline aborted due to quality gate failure") {
error errorString
}
}
}
}
}
stage('Publish') {
agent {
label 'master'
}
steps {
sh 'rm -rf built coverage .nyc_output node_modules test-results.xml package-lock.json .npmrc'
sh 'docker run --rm -w `pwd` -v `pwd`:`pwd` node:18.13.0 npm install --production --force'
sh 'docker run --rm -w `pwd` -v `pwd`:`pwd` node:18.13.0 npm run build'
withCredentials([file(credentialsId: 'node-npmrc-public-file', variable: 'FILE')]) {
sh 'docker run --rm -w `pwd` -v `pwd`:`pwd` -v $FILE:`pwd`/.npmrc node:18.13.0 ls -lah `pwd`'
sh 'docker run --rm -w `pwd` -v `pwd`:`pwd` -v $FILE:`pwd`/.npmrc node:18.13.0 cat `pwd`/.npmrc'
sh 'docker run --rm -w `pwd` -v `pwd`:`pwd` -v $FILE:`pwd`/.npmrc node:18.13.0 npm publish --access public'
}
}
}
}
post {
always {
deleteDir()
}
}
}