Search code examples
githubcontinuous-integrationgithub-actionsgithub-apigithub-cli

How to get list of previous job runs from GitHub Actions?


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.


Solution

  • 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.