This repository has been archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nodejs.groovy
254 lines (234 loc) · 6.98 KB
/
nodejs.groovy
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import com.concur.*;
concurPipeline = new Commands()
concurUtil = new Util()
workflowDoc = '''
title: NodeJS
overview: Execute any NPM, Grunt or Gulp task.
additional_resources:
- name: NodeJS Official Site
url: https://nodejs.org/en/
- name: NPM
url: https://www.npmjs.com
- name: Grunt
url: https://gruntjs.com
- name: Gulp
url: https://gulpjs.com
- name: Docker Images
url: https://hub.docker.com/_/node/
tools:
- type: String
name: dockerImage
section: nodejs
description: Docker image to run all NodeJS commands in.
- type: List
name: commandArgs
section: nodejs.npm
description: Additional arguments to the NPM commands.
- type: String
name: command
section: nodejs.npm
description: The NPM command to run within a nodejs.npm workflow step.
default: install
- type: String
name: npmRegistry
section: nodejs.npm
description: URL to an alternate NPM registry.
- type: List
name: commandArgs
section: nodejs.gulp
description: Additional arguments to a Gulp command.
- type: String
name: command
section: nodejs.gulp
description: The Gulp command to run within a nodejs.gulp workflow step.
default: install
- type: List
name: commandArgs
section: nodejs.grunt
description: Additional arguments to a Grunt command.
- type: String
name: command
section: nodejs.grunt
description: The Grunt command to run within a nodejs.grunt workflow step.
default: install
full_example: |
pipelines:
tools:
branches:
patterns:
feature: .+
tools:
nodejs:
buildImage: node:9.3-alpine
branches:
feature:
steps:
- nodejs:
- npm:
- docker:
- build:
- push:
'''
/*
description: Execute NPM tasks.
parameters:
- type: String
name: dockerImage
description: Docker image to run all NodeJS commands in.
- type: List
name: commandArgs
description: Additional arguments to the NPM commands.
- type: String
name: command
description: The NPM command to run within a nodejs.npm workflow step.
default: install
- type: String
name: npmRegistry
description: URL to an alternate NPM registry.
example: |
branches:
feature:
steps:
- nodejs:
# Simple
- node:
# Advanced
- node:
command: compile
*/
public npm(Map yml, Map args) {
String dockerImage = args?.buildImage ?: yml.tools?.nodejs?.buildImage
List commandArgs = args?.extraArgs ?: yml.tools?.nodejs?.npm?.extraArgs
String command = args?.command ?: yml.tools?.nodejs?.npm?.command ?: 'install'
// default to the npm cache from Artifactory
String npmRegistry = args?.registry ?: yml.tools?.nodejs?.npm?.registry
dockerImage = concurUtil.mustacheReplaceAll(dockerImage)
npmRegistry = concurUtil.mustacheReplaceAll(npmRegistry)
assert dockerImage : 'Workflows :: nodejs :: npm :: No [buildImage] provided in [tools.nodejs] or as a parameter to the nodejs.npm step.'
concurPipeline.debugPrint('Workflows :: nodejs :: npm', [
'args' : args,
'dockerImage' : dockerImage,
'commandArgs' : commandArgs,
'command' : command,
'npmRegistry' : npmRegistry
])
docker.image(dockerImage).inside('-u 0:0') {
if (npmRegistry) {
sh "npm config set registry $npmRegistry -g"
}
command = "npm $command"
if (commandArgs) {
command = "$command ${commandArgs.join(' ')}"
}
sh command
}
}
/*
description: Execute Gulp tasks.
parameters:
- type: String
name: dockerImage
description: Docker image to run all NodeJS commands in.
- type: List
name: commandArgs
description: Additional arguments to a Gulp command.
- type: String
name: command
description: The Gulp command to run within a nodejs.gulp workflow step.
default: install
example: |
branches:
feature:
steps:
- nodejs:
# Simple
- gulp:
# Advanced
- gulp:
name: compileScss
*/
public gulp(Map yml, Map args) {
String dockerImage = args?.buildImage ?: yml.tools?.nodejs?.buildImage
List commandArgs = args?.extraArgs ?: yml.tools?.nodejs?.gulp?.extraArgs
String command = args?.command ?: yml.tools?.nodejs?.gulp?.command ?: 'install'
dockerImage = concurUtil.mustacheReplaceAll(dockerImage)
assert dockerImage : "Workflows :: nodejs :: gulp :: No [buildImage] provided in [tools.nodejs] or as a parameter to the nodejs.gulp step."
concurPipeline.debugPrint('Workflows :: nodejs :: gulp', [
'args' : args,
'dockerImage' : dockerImage,
'commandArgs' : commandArgs,
'command' : command
])
docker.image(dockerImage).inside('-u 0:0') {
command = "gulp $command"
if (commandArgs) {
command = "$command ${commandArgs.join(' ')}"
}
sh command
}
}
/*
description: Execute Grunt tasks.
parameters:
- type: String
name: dockerImage
description: Docker image to run all NodeJS commands in.
- type: List
name: commandArgs
description: Additional arguments to a Grunt command.
- type: String
name: command
description: The Grunt command to run within a nodejs.grunt workflow step.
default: install
example: |
branches:
feature:
steps:
- nodejs:
# Simple
- grunt:
# Advanced
- grunt:
name: webpack
*/
public grunt(Map yml, Map args) {
String dockerImage = args?.buildImage ?: yml.tools?.nodejs?.buildImage
List commandArgs = args?.extraArgs ?: yml.tools?.nodejs?.grunt?.extraArgs
String command = args?.command ?: yml.tools?.nodejs?.grunt?.command ?: 'install'
dockerImage = concurUtil.mustacheReplaceAll(dockerImage)
assert dockerImage : "Workflows :: nodejs :: grunt :: No [buildImage] provided in [tools.nodejs] or as a parameter to the nodejs.grunt step."
concurPipeline.debugPrint('Workflows :: nodejs :: grunt', [
'args' : args,
'dockerImage' : dockerImage,
'commandArgs' : commandArgs,
'command' : command
])
docker.image(dockerImage).inside('-u 0:0') {
command = "grunt $command"
if (commandArgs) {
command = "$command ${commandArgs.join(' ')}"
}
sh command
}
}
/*
* Set the name of the stage dynamically.
*/
public getStageName(Map yml, Map args, String stepName) {
switch(stepName) {
case 'npm':
String command = args?.command ?: yml.tools?.nodejs?.npm?.command ?: 'install'
return "nodejs: npm: ${command}"
case 'gulp':
String command = args?.command ?: yml.tools?.nodejs?.gulp?.command ?: 'install'
return "nodejs: gulp: ${command}"
case 'grunt':
String command = args?.command ?: yml.tools?.nodejs?.grunt?.command ?: 'install'
return "nodejs: grunt: ${command}"
}
}
public tests(Map yml, Map args) {
String workflowName = 'nodejs'
println "Testing $workflowName"
}
return this;