Once I’ve retrieved the job id from the Insights Recent Runs of a workflow job. https://circleci.com/docs/api/v2/#get-recent-runs-of-a-workflow-job
How do I get the details of that job? The id given from that endpoint doesn’t correlate with job-number on the Get job details endpoint.
https://circleci.com/docs/api/v2/#get-job-details
Hi @mattiejean – welcome to Discuss!
The ID that is returned from the “Get recent runs of a workflow job” is the workflow ID and does not correlate to a specific job but more of a collection of jobs that ran in that workflow.
With that in mind I actually think the following endpoint would be more in line with what you are looking for:
https://circleci.com/docs/api/#recent-builds-for-a-single-project
This would be able to be utilized with the get job details endpoint – you would use the value in the build_num
attribute. So as an example:
curl https://circleci.com/api/v1.1/project/gh/<user>/<project>?circle-token=<token>&limit=30&filter=completed
Would give you a response like:
{
...
"vcs_revision" : "123",
"workflows" : {
"job_name" : "deploy",
"job_id" : "<job_id>",
"workflow_id" : "<workflow_id>", # This is actually that ID that is returned from the insights endpoint you referenced
"workspace_id" : "<workspace_id>",
"upstream_job_ids" : [ "1", "2" ],
"upstream_concurrency_map" : { },
"workflow_name" : "build-test-and-deploy"
"vcs_tag" : null,
"build_num" : 37,
Then that 37
would be the job number you pass into the get job details endpoint, like:
curl https://circleci.com/api/v2/project/gh/<user>/<project>/job/37?circle-token=<token>
Hopefully that helps!
thank you! that’s helpful.
The final end result I am hoping to achieve is a listing of failed job runs for a given job name. For example, the job name is “functional-tests-master” and I want to get a listing for all the times its failed and then have links to the details.
It looks like I could do that by programmatically filtering the “recent builds for a single project” endpoint you pointed me to. I was hoping that there was a more direct route, however.
You’re welcome, glad it was helpful, and thanks for the further details.
What you are looking for isn’t something we have a direct endpoint for, but I do believe you could use the recent builds endpoint to accomplish it, something like:
curl -s "https://circleci.com/api/v1.1/project/gh/<org_name>/<project_name>?circle-token=<token>&limit=100" | jq -r '.[] | select (.status? == "failed") | select (.workflows.job_name == "functional-tests-master") | {build_url, build_num, status, workflows}'
Should get you something like:
...
{
"build_url": "https://circleci.com/gh/<org_name>/<project>/54",
"build_num": 54,
"status": "failed",
"workflows": {
"job_name": "functional-tests-master",
"job_id": "<job_id>",
"workflow_id": "<workflow_id>",
"workspace_id": "<workspace_id>",
"upstream_job_ids": [],
"upstream_concurrency_map": {},
"workflow_name": "build-test-deploy"
}
}
...
that’s great! thanks for your help!
You’re welcome, happy to help!