githubgithub-actions

github actions get URL of test build


I can't seem to find out how to get the URL of a test workflow anywhere in the docs. I have a simple job which runs tests and on fail it needs to post the URL of the failed job to another web service.

I was expecting this to be in the default env vars but apparently not.

Thanks,


Solution

  • Here's how you construct the URL:

    ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
    

    2025 Update: There isn't a way to construct direct URL of the job. But you can use Rest API to do this.

    - name: Get Workflow Job URL
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        set -euo pipefail
        jobs_url="${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}/jobs"
        job_name="${{ github.job }}"
        job_id=$(curl -sSf "$jobs_url" \
          -H "Accept: application/vnd.github+json" \
          -H "Authorization: Bearer $GITHUB_TOKEN" \
          -H "X-GitHub-Api-Version: 2022-11-28" \
          | jq --arg job_name "$job_name" '.jobs[] | select(.name == $job_name) | .id')
        echo "Job ID: $job_id"
        echo "Job URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/$job_id"