-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·36 lines (27 loc) · 1.2 KB
/
index.js
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
let fs = require('fs');
function firePipeline(answers) {
let job_string = `${answers.repo_name}/${answers.branch_name}`;
let cred_string = `${answers.jenkins_username}:${answers.jenkins_token}`;
let cli_exe = `java -jar ${answers.cli_path} -auth ${cred_string} -http -s ${answers.jenkins_url}`;
let lint_string = '';
if (answers.is_declarative){
lint_string = `cat ${answers.jenkinsfile_path} | ${cli_exe} declarative-linter && `
}
let execution_string = `${lint_string} ` +
`cat ${answers.jenkinsfile_path} | ${cli_exe} replay-pipeline ${job_string} -n ${answers.build_number} && ` +
`${cli_exe} console ${job_string} -f`;
const {spawn} = require('child_process');
const child = spawn("sh", ["-c", execution_string]);
child.stdout.setEncoding('utf8').on('data', (chunk) => {
console.log(chunk);
});
child.stderr.setEncoding('utf8').on('data', (chunk) => {
console.log(chunk);
});
child.on('close', (code) => {
console.log(`child process exited with code ${code}`);
})
}
let answersFilepath = `${__dirname}/answers.json`;
answers = JSON.parse(fs.readFileSync(answersFilepath, 'utf8'));
firePipeline(answers);