Skip to content

Commit

Permalink
Add more logging to the job
Browse files Browse the repository at this point in the history
Signed-off-by: Akshay Sharma <akshay.sharma@fresha.com>
  • Loading branch information
akshaysharma096 committed Oct 16, 2024
1 parent b4171fc commit 010f49a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const request = require("request");
const core = require("@actions/core");
const util = require('util');
const util = require("util");

// if the API requests fail more than threshold, we will cause exit the script with error code
const FAILURE_THRESHOLD = 10;
Expand Down Expand Up @@ -84,9 +84,9 @@ async function getJobStatus(jobName, statusUrl) {
return new Promise((resolve, reject) =>
request(req, (err, res, body) => {
if (err) {
core.info(`Received an error: ${err.message}`);
clearTimeout(timer);
reject(err);
return;
}
core.info(`The response code from Jenkins API is: ${res.statusCode}`);
switch (res.statusCode) {
Expand Down Expand Up @@ -149,9 +149,17 @@ async function waitJenkinsJob(jobName, queueItemUrl, timestamp) {

try {
let buildData = await getJobStatus(jobName, buildUrl);

core.info(`buildData is: ${ util.inspect(buildData.result, {depth: null}) }`);


if (!buildData) {
core.info("buildData is empty - waiting....");
await sleep(sleepInterval);
continue;
}

core.info(
`buildData is: ${util.inspect(buildData.result, { depth: null })}`
);

if (buildData.result == "SUCCESS") {
core.info(
`>>> Job '${buildData.fullDisplayName}' completed successfully!`
Expand All @@ -174,9 +182,10 @@ async function waitJenkinsJob(jobName, queueItemUrl, timestamp) {
await sleep(sleepInterval);
continue;
} else {
throw new Error(
`Unexpected error in Job '${buildData.fullDisplayName}', ${error.message}`
core.info(
`Unexpected error happened in the Jenkinsjob (prod-to-env sync): ${error.message}`
);
throw new Error(`Prod-to-env sync job failed, ${error.message}`);
}
}
}
Expand Down

0 comments on commit 010f49a

Please sign in to comment.