Skip to content

Commit

Permalink
Canary tasks CI - check Succeeded or PartiallySucceeded (#19406)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisRumyantsev authored Dec 28, 2023
1 parent d93a4e1 commit 511930a
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions ci/ci-test-tasks/test-and-verify-v2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@ import { fetchBuildStatus, retryFailedJobsInBuild } from './helpers.Build';
import { fetchPipelines } from './helpers.Pipeline';
import { getBuildConfigs } from './helpers';

interface BuildResult { succeeded: boolean; message: string }
interface BuildResult { result: string; message: string }

const DISABLED = 'disabled';

const buildResultCode = {
0: 'None',
2: 'Succeeded',
4: 'PartiallySucceeded',
8: 'Failed',
32: 'Canceled'
};

const buildResultEnum = {
None: 'None',
Succeeded: 'Succeeded',
PartiallySucceeded: 'PartiallySucceeded',
Failed: 'Failed',
Canceled: 'Canceled'
};

async function main() {
const disabledPipelines: string[] = [];
const runningTestBuilds: Promise<BuildResult>[] = [];
Expand All @@ -23,18 +39,20 @@ async function main() {
}
}

let failed = false;
let failed: boolean = false;

Promise.all(runningTestBuilds).then(results => {
Promise.all(runningTestBuilds).then(buildResults => {
console.log('\nResults:');

results.map(result => {
if (!result.succeeded) {
result.message = `##vso[task.issue type=error]${result.message}`;
buildResults.map(buildResult => {
if (buildResult.result === buildResultEnum.PartiallySucceeded) {
buildResult.message = `##vso[task.issue type=warning]${buildResult.message}`;
} else if (buildResult.result !== buildResultEnum.Succeeded) {
buildResult.message = `##vso[task.issue type=error]${buildResult.message}`;
failed = true;
}

console.log(result.message);
console.log(buildResult.message);
});
}).catch(error => {
console.error(error);
Expand Down Expand Up @@ -68,10 +86,10 @@ async function runTaskPipelines(taskName: string): Promise<Promise<BuildResult>[

const runningBuilds: Promise<BuildResult>[] = [];
for (const config of configs) {
console.log(`Running tests for "${taskName}" task with config "${config}" for pipeline "${pipeline.name}"`)
console.log(`Running tests for "${taskName}" task with config "${config}" for pipeline "${pipeline.name}"`);
const pipelineBuild = await startTestPipeline(pipeline, config);

const buildPromise = new Promise<BuildResult>(resolve => completeBuild(taskName, pipelineBuild, resolve))
const buildPromise = new Promise<BuildResult>(resolve => completeBuild(taskName, pipelineBuild, resolve));
runningBuilds.push(buildPromise);
}

Expand Down Expand Up @@ -132,26 +150,28 @@ async function completeBuild(
if (++intervalAmount * intervalInSeconds >= buildTimeoutInSeconds) {
clearInterval(interval);

resolve({ succeeded: false, message: `Timeout to complete the ${stringifiedBuild} exceeded` });
resolve({ result: 'Timeout', message: `Timeout to complete the ${stringifiedBuild} exceeded` });
}

return;
}

if (buildStatus.result === 2) { // succeeded
clearInterval(interval);
const result = buildResultCode[buildStatus.result!];

resolve({ succeeded: true, message: `The ${stringifiedBuild} completed with result "${buildStatus.result}"` });
} else if (retryCount < maxRetries) {
if (
result !== buildResultEnum.Succeeded &&
result !== buildResultEnum.PartiallySucceeded &&
retryCount < maxRetries
) {
console.log(`Retrying failed jobs in ${stringifiedBuild}. Retry count: ${++retryCount} out of ${maxRetries}`);
await retryFailedJobsInBuild(pipelineBuild);
}
else {
} else {
clearInterval(interval);

resolve({ succeeded: false, message: `The ${stringifiedBuild} completed with result "${buildStatus.result}"` });
resolve({ result, message: `The ${stringifiedBuild} completed with result "${result}"` });
}
},

intervalInSeconds * 1000
);
}
Expand Down

0 comments on commit 511930a

Please sign in to comment.