ci: verify CircleCI job number before returning job url (#20483)
This commit is contained in:
parent
de3c1fae7f
commit
23066f8cce
1 changed files with 34 additions and 5 deletions
|
@ -86,13 +86,11 @@ async function circleCIcall (targetBranch, job, options) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log(`CircleCI release build workflow running at https://circleci.com/workflow-run/${workflowId} for ${job}.`)
|
console.log(`CircleCI release build workflow running at https://circleci.com/workflow-run/${workflowId} for ${job}.`)
|
||||||
const jobInfoUrl = `https://circleci.com/api/v2/workflow/${workflowId}/jobs`
|
const jobNumber = await getCircleCIJobNumber(workflowId)
|
||||||
const jobInfo = await circleCIRequest(jobInfoUrl, 'GET')
|
if (jobNumber === -1) {
|
||||||
if (!jobInfo.items || jobInfo.items.length !== 1) {
|
|
||||||
console.log('Error retrieving job for workflow, response was:', jobInfo)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const jobUrl = `https://circleci.com/gh/electron/electron/${jobInfo.items[0].job_number}`
|
const jobUrl = `https://circleci.com/gh/electron/electron/${jobNumber}`
|
||||||
console.log(`CircleCI release build request for ${job} successful. Check ${jobUrl} for status.`)
|
console.log(`CircleCI release build request for ${job} successful. Check ${jobUrl} for status.`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Error calling CircleCI: ', err)
|
console.log('Error calling CircleCI: ', err)
|
||||||
|
@ -121,6 +119,37 @@ async function getCircleCIWorkflowId (pipelineId) {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getCircleCIJobNumber (workflowId) {
|
||||||
|
const jobInfoUrl = `https://circleci.com/api/v2/workflow/${workflowId}/jobs`
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
const jobInfo = await circleCIRequest(jobInfoUrl, 'GET')
|
||||||
|
if (!jobInfo.items) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (jobInfo.items.length !== 1) {
|
||||||
|
console.log('Unxpected number of jobs, response was:', jobInfo)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (jobInfo.items[0].status) {
|
||||||
|
case 'not_running':
|
||||||
|
case 'queued':
|
||||||
|
case 'running': {
|
||||||
|
if (jobInfo.items[0].job_number && !isNaN(jobInfo.items[0].job_number)) {
|
||||||
|
return jobInfo.items[0].job_number
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'error': {
|
||||||
|
console.log('Error retrieving jobs, response was:', jobInfo)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 5000))
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
async function circleCIRequest (url, method, requestBody) {
|
async function circleCIRequest (url, method, requestBody) {
|
||||||
return makeRequest({
|
return makeRequest({
|
||||||
auth: {
|
auth: {
|
||||||
|
|
Loading…
Reference in a new issue