Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canary tasks CI - check Succeeded or PartiallySucceeded #19406

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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