8000 GitHub - jenseng/get-job-uuid: Get the UUID for the current GitHub Actions job
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jenseng/get-job-uuid

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

get-job-uuid

This action returns the UUID for the current job.

Notably, this UUID is generated by GitHub and can be used to identify the corresponding job record via API calls.

Usage

- uses: jenseng/get-job-uuid@v1
  id: job-uuid
- env:
    uuid: ${{ steps.job-uuid.outputs.uuid }}
  run: |
    echo "job uuid: $uuid"

On the API side, this UUID is exposed as the corresponding check run's external_id. So to get from the UUID to the job ID, you can do something like the following:

- name: Find job id
  shell: bash
  env:
    GITHUB_TOKEN: ${{ github.token }}
    uuid: ${{ steps.job-uuid.outputs.uuid }}
  run: |
    # first find the check_suite_id for this run
    check_suite_id="$(
      gh api "repos/{owner}/{repo}/actions/runs/${GITHUB_RUN_ID}" --jq .check_suite_id
    )"

    # then use the check_suite_id and uuid to find the job id
    # (the check run id _is_ the job id)
    job_id="$(
      gh api "repos/{owner}/{repo}/check-suites/${check_suite_id}/check-runs" \
        --jq ".check_runs[] | select(.external_id == env.uuid) | .id"
    )"
    echo "::notice::Job ID: ${job_id}"

For example, you can see the extracted job ids from this repo's own GitHub Actions jobs.

How does it work?

Although GitHub doesn't directly expose the job UUID, it can be reliably extracted from the worker diagnostic logs that get generated for every job. Even if debug logging is disabled, these logs are still present and accessible within the job. The basic process is as follows:

  1. The action finds the Runner.Worker process information.
  2. The action infers the _diag directory relative to the location of the Runner.Worker binary. This is necessary since the directory may be in a different location depending on the runner type (e.g. ubuntu-latest vs windows-latest vs self-hosted)
  3. The action extracts the UUID from the worker log file in the _diag directory.

Limitations

This action is known not to work within containerized jobs, since the host processes and file system are not accessible from within the container.

License

The scripts and documentation in this project are released under the ISC License

About

Get the UUID for the current GitHub Actions job

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
0