-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathJenkinsfile
More file actions
97 lines (86 loc) · 3.18 KB
/
Jenkinsfile
File metadata and controls
97 lines (86 loc) · 3.18 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
87
88
89
90
91
92
93
94
95
96
97
pipeline {
agent {
kubernetes (
k8sAgent(
name: 'nodeJs',
nodeJS: "14.17.0-slim",
idleMinutes: params.POD_IDLE_MINUTES
)
)
}
parameters {
string(name: 'POD_IDLE_MINUTES', defaultValue: '0', description: 'Number of minutes pod will stay idle post build')
string(name: 'VERSION_NUMBER', description: 'InsightAppSec Github Scan tag version number')
booleanParam(name: 'RUN_PIPELINE', defaultValue: false, description: 'Option to build files and create tag')
}
stages {
//run unit tests
stage('Unit tests') {
steps {
container("node"){
script {
sh """
npm install --save-dev jest
npm t
"""
}
}
}
}
//create updated dist/index.js file
stage('Prepare build') {
when {
expression {
params.RUN_PIPELINE
!params.VERSION_NUMBER.isEmpty()
}
}
steps {
container("node"){
script {
sh """
if [ -d "node_modules" ]
then
rm -r node_modules
fi
if [ -f "dist/index.js" ]
then
rm dist/index.js
fi
npm install --production
npm i -g @vercel/ncc@0.31.1
npm run build
"""
}
}
}
}
stage('Create tag') {
when {
expression {
params.RUN_PIPELINE
!params.VERSION_NUMBER.isEmpty()
}
}
steps {
withCredentials([usernamePassword(credentialsId: 'github-app-key', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh label: 'git config user.email',
script: 'git config --global user.email github_serviceaccounts+$USERNAME@rapid7.com'
sh label: 'git config user.name',
script: 'git config --global user.name $USERNAME'
//check-in index file, create tag and release
sh """
if [ -f "dist/index.js" ]; then
git pull --ff-only https://${USERNAME}:${PASSWORD}@github.com/rapid7/insightappsec-scan-github-actions
git add dist/index.js
git commit -m "Updating index.js file"
git push https://${USERNAME}:${PASSWORD}@github.com/rapid7/insightappsec-scan-github-actions
git tag ${params.VERSION_NUMBER}
git push https://${USERNAME}:${PASSWORD}@github.com/rapid7/insightappsec-scan-github-actions ${params.VERSION_NUMBER}
fi
"""
}
}
}
}
}