0

I want to see history of successful/failed job runs to see if job is stable enough to make it required. Is there a way to show a list of about 100 previous runs of one particular job? Currently I see only list of workflows and I have to click trough each of them to see status of this job.

VladasZs
  • 87
  • 1
  • 11

1 Answers1

1

You could list workflow runs using the Github API.

Inside the response body, there is a jobs_url field that you can use to get all the workflow jobs details.

Example with a personal workflow

URL to list all workflow runs from the repositories: https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/actions/runs

URL to list jobs details from a specific workflow run: https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/actions/runs/1265017898/jobs

{
  "total_count": 3,
  "jobs": [
    {
      "id": 3684793326,
      "run_id": 1265017898,
      "run_url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/actions/runs/1265017898",
      "node_id": "CR_kwDOFPk6vM7boXvu",
      "head_sha": "ed9977f4ced9ae12d50401a773046197a59c2575",
      "url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/actions/jobs/3684793326",
      "html_url": "https://github.com/GuillaumeFalourd/poc-github-actions/runs/3684793326",
      "status": "completed",
      "conclusion": "success",
      "started_at": "2021-09-23T08:16:30Z",
      "completed_at": "2021-09-23T08:16:32Z",
      "name": "job2",
      "steps": [
        {
          "name": "Set up job",
          "status": "completed",
          "conclusion": "success",
          "number": 1,
          "started_at": "2021-09-23T08:16:30.000Z",
          "completed_at": "2021-09-23T08:16:31.000Z"
        },
        {
          "name": "Run Commands with WORKFLOW variable",
          "status": "completed",
          "conclusion": "skipped",
          "number": 2,
          "started_at": "2021-09-23T08:16:31.000Z",
          "completed_at": "2021-09-23T08:16:31.000Z"
        },
        {
          "name": "Run Commands with JOB variable",
          "status": "completed",
          "conclusion": "success",
          "number": 3,
          "started_at": "2021-09-23T08:16:31.000Z",
          "completed_at": "2021-09-23T08:16:32.000Z"
        },
        {
          "name": "Complete job",
          "status": "completed",
          "conclusion": "success",
          "number": 4,
          "started_at": "2021-09-23T08:16:32.000Z",
          "completed_at": "2021-09-23T08:16:32.000Z"
        }
      ],
      "check_run_url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/check-runs/3684793326"
    },
    {
      "id": 3684793388,
      "run_id": 1265017898,
      "run_url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/actions/runs/1265017898",
      "node_id": "CR_kwDOFPk6vM7boXws",
      "head_sha": "ed9977f4ced9ae12d50401a773046197a59c2575",
      "url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/actions/jobs/3684793388",
      "html_url": "https://github.com/GuillaumeFalourd/poc-github-actions/runs/3684793388",
      "status": "completed",
      "conclusion": "success",
      "started_at": "2021-09-23T08:16:33Z",
      "completed_at": "2021-09-23T08:16:34Z",
      "name": "job1",
      "steps": [
        {
          "name": "Set up job",
          "status": "completed",
          "conclusion": "success",
          "number": 1,
          "started_at": "2021-09-23T08:16:33.000Z",
          "completed_at": "2021-09-23T08:16:33.000Z"
        },
        {
          "name": "Run Commands with various variables",
          "status": "completed",
          "conclusion": "success",
          "number": 2,
          "started_at": "2021-09-23T08:16:33.000Z",
          "completed_at": "2021-09-23T08:16:34.000Z"
        },
        {
          "name": "Complete job",
          "status": "completed",
          "conclusion": "success",
          "number": 3,
          "started_at": "2021-09-23T08:16:34.000Z",
          "completed_at": "2021-09-23T08:16:34.000Z"
        }
      ],
      "check_run_url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/check-runs/3684793388"
    },
    {
      "id": 3684793444,
      "run_id": 1265017898,
      "run_url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/actions/runs/1265017898",
      "node_id": "CR_kwDOFPk6vM7boXxk",
      "head_sha": "ed9977f4ced9ae12d50401a773046197a59c2575",
      "url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/actions/jobs/3684793444",
      "html_url": "https://github.com/GuillaumeFalourd/poc-github-actions/runs/3684793444",
      "status": "completed",
      "conclusion": "success",
      "started_at": "2021-09-23T08:16:32Z",
      "completed_at": "2021-09-23T08:16:33Z",
      "name": "job3",
      "steps": [
        {
          "name": "Set up job",
          "status": "completed",
          "conclusion": "success",
          "number": 1,
          "started_at": "2021-09-23T08:16:32.000Z",
          "completed_at": "2021-09-23T08:16:32.000Z"
        },
        {
          "name": "Set the value",
          "status": "completed",
          "conclusion": "success",
          "number": 2,
          "started_at": "2021-09-23T08:16:32.000Z",
          "completed_at": "2021-09-23T08:16:32.000Z"
        },
        {
          "name": "Use the value",
          "status": "completed",
          "conclusion": "success",
          "number": 3,
          "started_at": "2021-09-23T08:16:32.000Z",
          "completed_at": "2021-09-23T08:16:33.000Z"
        },
        {
          "name": "Complete job",
          "status": "completed",
          "conclusion": "success",
          "number": 4,
          "started_at": "2021-09-23T08:16:33.000Z",
          "completed_at": "2021-09-23T08:16:33.000Z"
        }
      ],
      "check_run_url": "https://api.github.com/repos/GuillaumeFalourd/poc-github-actions/check-runs/3684793444"
    }
  ]
}

Using those datas, and to achieve what you want (to check a particular job history), you could create a script to extract all jobs from a specific workflow (filter using the workflow name, here I used 10 - Environment Workflow) with the first URL doing loops, then use the workflow jobs details from the second URL to extract the job datas (filter using the job name, here we could use job2, as the ids field are all unique and generated for each run) doing loops again.

That workaround may be a bit verbose and will need many requests to the API (so it's not ideal due to the rate limit), but for what I searched there don't seem to have another solution to get what you want at the moment.

GuiFalourd
  • 15,523
  • 8
  • 44
  • 71
  • Hey! I am trying to get the status of the previous run of a workflow of a branch. Reason: In 1st run of my workflow "test" job got failed, now in my 2nd run I want to get the status of 1st run of the "test" job for my branch only and if was failed then don't skip. Do know any api for that or any suggestion on who to achieve above scenario – gamechanger17 Nov 10 '22 at 16:04
  • Hey! You could follow the same behavior I detailed in the answer above. It's just that case, you would need to get the ID of the last run (which will be the second higher one if you list all, or the first one if you list only the completed one) when consulting the API on the current run. Then, you would need to extract the job `status` value to check if it was failed or successful. Based on that, if you need this operation in a job, you could set this result in an output and check its value to trigger or not subsequent jobs. – GuiFalourd Nov 10 '22 at 21:09