buildnator-personal 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/buildnator.client.ts +144 -58
- package/dist/buildnator.client.js +509 -775
- package/index.ts +2 -0
- package/package.json +5 -4
- package/tsconfig.json +7 -2
- package/types.ts +1 -0
package/buildnator.client.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as https from "https";
|
|
|
3
3
|
import type { BuildnatorConfig, JobsConfig, QueryValue } from "./types";
|
|
4
4
|
|
|
5
5
|
const DEFAULT_BUILD_DELAY_MS = 15000;
|
|
6
|
+
const DEFAULT_FILA_DELAY_MS = 15000;
|
|
6
7
|
|
|
7
8
|
const DEFAULT_JOBS: JobsConfig = {
|
|
8
9
|
agmCompila: "/job/GCS-AGM-Compila%C3%A7%C3%A3o-Automatizada",
|
|
@@ -17,6 +18,7 @@ const DEFAULT_JOBS: JobsConfig = {
|
|
|
17
18
|
unificarCommits: "/job/GCS-Unificar-commits",
|
|
18
19
|
criarbackup: "job/GCS-CriarBackup",
|
|
19
20
|
recriarBranch: "view/Ger%C3%AAncia%20de%20Configura%C3%A7%C3%A3o/job/GCS-RecriarBranch/"
|
|
21
|
+
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
function normalizeBaseUrl(url: string): string {
|
|
@@ -28,6 +30,7 @@ export class BuildnatorClient {
|
|
|
28
30
|
private readonly auth: { username: string; password: string };
|
|
29
31
|
private readonly jobs: JobsConfig;
|
|
30
32
|
private readonly buildDelayMs: number;
|
|
33
|
+
private readonly filaDelayMs: number;
|
|
31
34
|
|
|
32
35
|
constructor(private readonly config: BuildnatorConfig) {
|
|
33
36
|
if (!config?.jenkins?.baseUrl || !config.jenkins.user || !config.jenkins.token) {
|
|
@@ -46,25 +49,9 @@ export class BuildnatorClient {
|
|
|
46
49
|
httpsAgent,
|
|
47
50
|
});
|
|
48
51
|
|
|
49
|
-
/*if (config.gateway?.baseUrl) {
|
|
50
|
-
this.gateway = axios.create({
|
|
51
|
-
baseURL: normalizeBaseUrl(config.gateway.baseUrl),
|
|
52
|
-
httpsAgent,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
this.gateway.interceptors.request.use((req) => {
|
|
56
|
-
const token = config.gateway?.restrictToken;
|
|
57
|
-
if (token) {
|
|
58
|
-
const url = new URL(req.url ?? "", req.baseURL);
|
|
59
|
-
url.searchParams.append("token", token);
|
|
60
|
-
req.url = url.toString();
|
|
61
|
-
}
|
|
62
|
-
return req;
|
|
63
|
-
});
|
|
64
|
-
}*/
|
|
65
|
-
|
|
66
52
|
this.jobs = { ...DEFAULT_JOBS, ...(config.jobs ?? {}) };
|
|
67
53
|
this.buildDelayMs = config.delays?.buildTriggerMs ?? DEFAULT_BUILD_DELAY_MS;
|
|
54
|
+
this.filaDelayMs = config.delays?.filaMs ?? DEFAULT_FILA_DELAY_MS
|
|
68
55
|
}
|
|
69
56
|
|
|
70
57
|
private sleep(ms: number): Promise<void> {
|
|
@@ -76,6 +63,11 @@ export class BuildnatorClient {
|
|
|
76
63
|
return res.data;
|
|
77
64
|
}
|
|
78
65
|
|
|
66
|
+
private async jenkinsPostNoData(path: string, params?: Record<string, QueryValue>) {
|
|
67
|
+
const res = await this.jenkins.post(path, null, { auth: this.auth, params });
|
|
68
|
+
return res;
|
|
69
|
+
}
|
|
70
|
+
|
|
79
71
|
private async jenkinsGet(path: string, params?: Record<string, QueryValue>) {
|
|
80
72
|
const res = await this.jenkins.get(path, { auth: this.auth, params });
|
|
81
73
|
return res.data;
|
|
@@ -91,15 +83,22 @@ export class BuildnatorClient {
|
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
async compilaAGM(branch: string, dirPrefix: string, diretivas: string, version: string): Promise<any> {
|
|
94
|
-
await this.
|
|
86
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.agmCompila}/buildWithParameters`, {
|
|
95
87
|
branch,
|
|
96
88
|
dirPrefix,
|
|
97
89
|
diretivas,
|
|
98
90
|
version,
|
|
99
91
|
});
|
|
100
|
-
await this.sleep(this.buildDelayMs);
|
|
92
|
+
/*await this.sleep(this.buildDelayMs);
|
|
101
93
|
const numbuild = await this.jenkinsPost(`${this.jobs.agmCompila}/api/json`);
|
|
102
|
-
return numbuild.builds[0].number
|
|
94
|
+
return numbuild.builds[0].number;*/
|
|
95
|
+
|
|
96
|
+
const location = retorno.headers['location'];
|
|
97
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
98
|
+
|
|
99
|
+
await this.sleep(this.filaDelayMs);
|
|
100
|
+
const id = await this.consultarFila(queueId)
|
|
101
|
+
return id
|
|
103
102
|
}
|
|
104
103
|
|
|
105
104
|
async consultaJenkinsAGM(id: number): Promise<any> {
|
|
@@ -125,7 +124,7 @@ export class BuildnatorClient {
|
|
|
125
124
|
modulos: string,
|
|
126
125
|
gerarVersao: boolean,
|
|
127
126
|
): Promise<any> {
|
|
128
|
-
await this.
|
|
127
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.agbCompila}/buildWithParameters`, {
|
|
129
128
|
branch,
|
|
130
129
|
dirPrefix,
|
|
131
130
|
diretivas,
|
|
@@ -133,9 +132,16 @@ export class BuildnatorClient {
|
|
|
133
132
|
modulosOpcionais: modulos,
|
|
134
133
|
gerarVersao,
|
|
135
134
|
});
|
|
136
|
-
await this.sleep(this.buildDelayMs);
|
|
135
|
+
/*await this.sleep(this.buildDelayMs);
|
|
137
136
|
const numbuild = await this.jenkinsPost(`${this.jobs.agbCompila}/api/json`);
|
|
138
|
-
return numbuild.builds[0].number
|
|
137
|
+
return numbuild.builds[0].number;*/
|
|
138
|
+
|
|
139
|
+
const location = retorno.headers['location'];
|
|
140
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
141
|
+
|
|
142
|
+
await this.sleep(this.filaDelayMs);
|
|
143
|
+
const id = await this.consultarFila(queueId)
|
|
144
|
+
return id
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
async consultaJenkinsAGB(id: number): Promise<any> {
|
|
@@ -164,6 +170,7 @@ export class BuildnatorClient {
|
|
|
164
170
|
versionOld?: string | null,
|
|
165
171
|
datahora?: any
|
|
166
172
|
): Promise<any> {
|
|
173
|
+
let retorno
|
|
167
174
|
if (alterarDTHR) {
|
|
168
175
|
if (!versionOld) {
|
|
169
176
|
throw new Error("versionOld eh obrigatorio quando alterarDTHR=true");
|
|
@@ -221,7 +228,7 @@ export class BuildnatorClient {
|
|
|
221
228
|
String(somasegundos).padStart(2, "0"),
|
|
222
229
|
].join(":");
|
|
223
230
|
|
|
224
|
-
|
|
231
|
+
retorno = await this.jenkinsPostNoData(`${this.jobs.agbCompilaVersao}/buildWithParameters`, {
|
|
225
232
|
branch,
|
|
226
233
|
dirPrefix,
|
|
227
234
|
diretivas,
|
|
@@ -232,7 +239,7 @@ export class BuildnatorClient {
|
|
|
232
239
|
data,
|
|
233
240
|
});
|
|
234
241
|
} else {
|
|
235
|
-
await this.
|
|
242
|
+
retorno = await this.jenkinsPostNoData(`${this.jobs.agbCompilaVersao}/buildWithParameters`, {
|
|
236
243
|
branch,
|
|
237
244
|
dirPrefix,
|
|
238
245
|
diretivas,
|
|
@@ -242,9 +249,16 @@ export class BuildnatorClient {
|
|
|
242
249
|
});
|
|
243
250
|
}
|
|
244
251
|
|
|
245
|
-
await this.sleep(this.buildDelayMs);
|
|
252
|
+
/*await this.sleep(this.buildDelayMs);
|
|
246
253
|
const numbuild = await this.jenkinsPost(`${this.jobs.agbCompilaVersao}/api/json`);
|
|
247
|
-
return numbuild.builds[0].number
|
|
254
|
+
return numbuild.builds[0].number;*/
|
|
255
|
+
|
|
256
|
+
const location = retorno.headers['location'];
|
|
257
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
258
|
+
|
|
259
|
+
await this.sleep(this.filaDelayMs);
|
|
260
|
+
const id = await this.consultarFila(queueId)
|
|
261
|
+
return id
|
|
248
262
|
}
|
|
249
263
|
|
|
250
264
|
async consultaVesaoJenkinsAGB(id: number): Promise<any> {
|
|
@@ -283,43 +297,71 @@ export class BuildnatorClient {
|
|
|
283
297
|
}
|
|
284
298
|
|
|
285
299
|
async liberaAGM(diretorio: string, baseline: string): Promise<any> {
|
|
286
|
-
await this.
|
|
300
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.qaAgmLibera}/buildWithParameters`, {
|
|
287
301
|
diretorioExecutaveis: diretorio,
|
|
288
302
|
baselineExecutaveis: baseline,
|
|
289
303
|
});
|
|
290
|
-
await this.sleep(this.buildDelayMs);
|
|
304
|
+
/*await this.sleep(this.buildDelayMs);
|
|
291
305
|
const numbuild = await this.jenkinsPost(`${this.jobs.qaAgmLibera}/api/json`);
|
|
292
|
-
return numbuild.builds[0].number
|
|
306
|
+
return numbuild.builds[0].number;*/
|
|
307
|
+
|
|
308
|
+
const location = retorno.headers['location'];
|
|
309
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
310
|
+
|
|
311
|
+
await this.sleep(this.filaDelayMs);
|
|
312
|
+
const id = await this.consultarFila(queueId)
|
|
313
|
+
return id
|
|
293
314
|
}
|
|
294
315
|
|
|
295
316
|
async liberaAGB(diretorio: string, baseline: string): Promise<any> {
|
|
296
|
-
await this.
|
|
317
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.qaTaAgbLibera}/buildWithParameters`, {
|
|
297
318
|
diretorioExecutaveis: diretorio,
|
|
298
319
|
baselineExecutaveis: baseline,
|
|
299
320
|
});
|
|
300
|
-
await this.sleep(this.buildDelayMs);
|
|
321
|
+
/*await this.sleep(this.buildDelayMs);
|
|
301
322
|
const numbuild = await this.jenkinsPost(`${this.jobs.qaTaAgbLibera}/api/json`);
|
|
302
|
-
return numbuild.builds[0].number
|
|
323
|
+
return numbuild.builds[0].number;*/
|
|
324
|
+
|
|
325
|
+
const location = retorno.headers['location'];
|
|
326
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
327
|
+
|
|
328
|
+
await this.sleep(this.filaDelayMs);
|
|
329
|
+
const id = await this.consultarFila(queueId)
|
|
330
|
+
return id
|
|
303
331
|
}
|
|
304
332
|
|
|
305
333
|
async liberaAGMEspecifica(diretorio: string, baseline: string): Promise<any> {
|
|
306
|
-
await this.
|
|
334
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.qaAgmLiberaEspecifica}/buildWithParameters`, {
|
|
307
335
|
diretorioExecutaveis: diretorio,
|
|
308
336
|
baselineExecutaveis: baseline,
|
|
309
337
|
});
|
|
310
|
-
await this.sleep(this.buildDelayMs);
|
|
338
|
+
/*await this.sleep(this.buildDelayMs);
|
|
311
339
|
const numbuild = await this.jenkinsPost(`${this.jobs.qaAgmLiberaEspecifica}/api/json`);
|
|
312
|
-
return numbuild.builds[0].number
|
|
340
|
+
return numbuild.builds[0].number;*/
|
|
341
|
+
|
|
342
|
+
const location = retorno.headers['location'];
|
|
343
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
344
|
+
|
|
345
|
+
await this.sleep(this.filaDelayMs);
|
|
346
|
+
const id = await this.consultarFila(queueId)
|
|
347
|
+
return id
|
|
313
348
|
}
|
|
314
349
|
|
|
315
350
|
async liberaAGBEspecifica(diretorio: string, baseline: string): Promise<any> {
|
|
316
|
-
await this.
|
|
351
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.qaTaAgbLiberaEspecifica}/buildWithParameters`, {
|
|
317
352
|
diretorioExecutaveis: diretorio,
|
|
318
353
|
baselineExecutaveis: baseline,
|
|
319
354
|
});
|
|
320
|
-
await this.sleep(this.buildDelayMs);
|
|
355
|
+
/*await this.sleep(this.buildDelayMs);
|
|
321
356
|
const numbuild = await this.jenkinsPost(`${this.jobs.qaTaAgbLiberaEspecifica}/api/json`);
|
|
322
|
-
return numbuild.builds[0].number
|
|
357
|
+
return numbuild.builds[0].number;*/
|
|
358
|
+
|
|
359
|
+
const location = retorno.headers['location'];
|
|
360
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
361
|
+
|
|
362
|
+
await this.sleep(this.filaDelayMs);
|
|
363
|
+
const id = await this.consultarFila(queueId)
|
|
364
|
+
return id
|
|
323
365
|
}
|
|
324
366
|
|
|
325
367
|
async consultaLiberaEspecifica(id: number, projeto: string): Promise<any> {
|
|
@@ -367,13 +409,20 @@ export class BuildnatorClient {
|
|
|
367
409
|
}
|
|
368
410
|
|
|
369
411
|
async PublicarDllsNuGet(versao: string, dirPrefix: string): Promise<any> {
|
|
370
|
-
await this.
|
|
412
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.publicarDllsNuget}/buildWithParameters`, {
|
|
371
413
|
version: versao,
|
|
372
414
|
diretoriobaseversao: dirPrefix,
|
|
373
415
|
});
|
|
374
|
-
await this.sleep(this.buildDelayMs);
|
|
416
|
+
/*await this.sleep(this.buildDelayMs);
|
|
375
417
|
const numbuild = await this.jenkinsPost(`${this.jobs.publicarDllsNuget}/api/json`);
|
|
376
|
-
return numbuild.builds[0].number
|
|
418
|
+
return numbuild.builds[0].number;*/
|
|
419
|
+
|
|
420
|
+
const location = retorno.headers['location'];
|
|
421
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
422
|
+
|
|
423
|
+
await this.sleep(this.filaDelayMs);
|
|
424
|
+
const id = await this.consultarFila(queueId)
|
|
425
|
+
return id
|
|
377
426
|
}
|
|
378
427
|
|
|
379
428
|
async consultaPublicarDllsNuGet(id: number): Promise<any> {
|
|
@@ -392,12 +441,19 @@ export class BuildnatorClient {
|
|
|
392
441
|
}
|
|
393
442
|
|
|
394
443
|
async testeTaVersaoEvolutiva(diretorioExecutaveis: string): Promise<any> {
|
|
395
|
-
await this.
|
|
444
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.testeTaVersaoEvolutiva}/buildWithParameters`, {
|
|
396
445
|
diretorioExecutaveis,
|
|
397
446
|
});
|
|
398
|
-
await this.sleep(this.buildDelayMs);
|
|
447
|
+
/*await this.sleep(this.buildDelayMs);
|
|
399
448
|
const numbuild = await this.jenkinsPost(`${this.jobs.testeTaVersaoEvolutiva}/api/json`);
|
|
400
|
-
return numbuild.builds[0].number
|
|
449
|
+
return numbuild.builds[0].number;*/
|
|
450
|
+
|
|
451
|
+
const location = retorno.headers['location'];
|
|
452
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
453
|
+
|
|
454
|
+
await this.sleep(this.filaDelayMs);
|
|
455
|
+
const id = await this.consultarFila(queueId)
|
|
456
|
+
return id
|
|
401
457
|
}
|
|
402
458
|
|
|
403
459
|
async consultatesteTaVersaoEvolutiva(id: any): Promise<any> {
|
|
@@ -416,13 +472,20 @@ export class BuildnatorClient {
|
|
|
416
472
|
}
|
|
417
473
|
|
|
418
474
|
async unificarCommits(branch: string, sistema: string): Promise<any> {
|
|
419
|
-
await this.
|
|
475
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.unificarCommits}/buildWithParameters`, {
|
|
420
476
|
Branch: branch,
|
|
421
477
|
repositorio: sistema,
|
|
422
478
|
});
|
|
423
|
-
await this.sleep(this.buildDelayMs);
|
|
479
|
+
/*await this.sleep(this.buildDelayMs);
|
|
424
480
|
const numbuild = await this.jenkinsPost(`${this.jobs.unificarCommits}/api/json`);
|
|
425
|
-
return numbuild.builds[0].number
|
|
481
|
+
return numbuild.builds[0].number;*/
|
|
482
|
+
|
|
483
|
+
const location = retorno.headers['location'];
|
|
484
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
485
|
+
|
|
486
|
+
await this.sleep(this.filaDelayMs);
|
|
487
|
+
const id = await this.consultarFila(queueId)
|
|
488
|
+
return id
|
|
426
489
|
}
|
|
427
490
|
|
|
428
491
|
async consultarUnificarCommits(id: any): Promise<any> {
|
|
@@ -474,13 +537,17 @@ export class BuildnatorClient {
|
|
|
474
537
|
}
|
|
475
538
|
|
|
476
539
|
async criarBCK(branch: string, sistema: string): Promise<any> {
|
|
477
|
-
await this.
|
|
540
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.criarbackup}/buildWithParameters`, {
|
|
478
541
|
branch: branch,
|
|
479
542
|
repositorio: sistema,
|
|
480
543
|
});
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
|
|
544
|
+
|
|
545
|
+
const location = retorno.headers['location'];
|
|
546
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
547
|
+
|
|
548
|
+
await this.sleep(this.filaDelayMs);
|
|
549
|
+
const id = await this.consultarFila(queueId)
|
|
550
|
+
return id
|
|
484
551
|
}
|
|
485
552
|
|
|
486
553
|
async consultarCriarBCK(id: any): Promise<any> {
|
|
@@ -503,15 +570,22 @@ export class BuildnatorClient {
|
|
|
503
570
|
}
|
|
504
571
|
|
|
505
572
|
async RecriarBranch(branch: string, sistema: string, branchBackup: string): Promise<any> {
|
|
506
|
-
await this.
|
|
573
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.recriarBranch}/buildWithParameters`, {
|
|
507
574
|
branch: branch,
|
|
508
575
|
repositorio: sistema,
|
|
509
576
|
branchBackup: branchBackup
|
|
510
577
|
|
|
511
578
|
});
|
|
512
|
-
await this.sleep(this.buildDelayMs);
|
|
579
|
+
/*await this.sleep(this.buildDelayMs);
|
|
513
580
|
const numbuild = await this.jenkinsPost(`${this.jobs.recriarBranch}/api/json`);
|
|
514
|
-
return numbuild.builds[0].number
|
|
581
|
+
return numbuild.builds[0].number;*/
|
|
582
|
+
|
|
583
|
+
const location = retorno.headers['location'];
|
|
584
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
585
|
+
|
|
586
|
+
await this.sleep(this.filaDelayMs);
|
|
587
|
+
const id = await this.consultarFila(queueId)
|
|
588
|
+
return id
|
|
515
589
|
}
|
|
516
590
|
|
|
517
591
|
async consultarRecriarBranch(id: any): Promise<any> {
|
|
@@ -519,13 +593,25 @@ export class BuildnatorClient {
|
|
|
519
593
|
const numbuild = await this.jenkinsPost(`${this.jobs.recriarBranch}/${id}/api/json`);
|
|
520
594
|
if (numbuild && numbuild.inProgress === false) {
|
|
521
595
|
if (numbuild.result === "SUCCESS") {
|
|
522
|
-
return { terminado: true, resultado: true, tipo: "recriarBranch", retorno: numbuild.result};
|
|
596
|
+
return { terminado: true, resultado: true, tipo: "recriarBranch", retorno: numbuild.result };
|
|
523
597
|
}
|
|
524
598
|
return { terminado: true, resultado: false, tipo: "recriarBranch", retorno: numbuild.result };
|
|
525
599
|
}
|
|
526
|
-
return { terminado: false, resultado: false, tipo: "recriarBranch", retorno: numbuild?.result};
|
|
600
|
+
return { terminado: false, resultado: false, tipo: "recriarBranch", retorno: numbuild?.result };
|
|
601
|
+
} catch {
|
|
602
|
+
return { terminado: true, resultado: false, tipo: "recriarBranch", retorno: "erro interno" };
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
async consultarFila(id: any): Promise<any> {
|
|
607
|
+
try {
|
|
608
|
+
const retorno = await this.jenkinsGet(`/queue/item/${id}/api/json`);
|
|
609
|
+
if (retorno && retorno.executable) {
|
|
610
|
+
return retorno.executable.number
|
|
611
|
+
}
|
|
612
|
+
return -1
|
|
527
613
|
} catch {
|
|
528
|
-
return
|
|
614
|
+
return -1
|
|
529
615
|
}
|
|
530
616
|
}
|
|
531
617
|
}
|