Skip to content

ReeganExE/github-action-job-id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ReeganExE/github-action-job-id

Since Github action doesn't expose job details (ID, URL) to the environment. This action will expose those through environment variables. Just include the action step, no passing arguments!

name: "Test"
on:
  workflow_dispatch:
jobs:
  Test:
    name: This is a test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: ReeganExE/github-action-job-id@v1.0

      - run: |
          echo $GH_JOB_0_ID
          env | grep GH_JOB

By default, it exposes env variables as $GH_JOB_<JOB_INDEX>_ID. If you want to use job name instead, add the arg expose-name: true.

Note: the sepcial characters in the job name will be replaced by _ character

name: "Test"
on:
  workflow_dispatch:
jobs:
  Test:
    name: This is a test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: ReeganExE/github-action-job-id@v1.0
        with:
          expose-name: true

      - run: |
          echo $GH_JOB_0_ID
          echo $GH_JOB_This_is_a_test_ID
          env | grep GH_JOB
  Job2:
    name: Job2
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: ReeganExE/github-action-job-id@v1.0
        with:
          expose-name: true

      - run: |
          echo $GH_JOB_1_ID
          echo $GH_JOB_Job2_ID
          env | grep GH_JOB
  Job3:
    name: Job3
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: ReeganExE/github-action-job-id@v1.0
        with:
          expose-name: true

      - run: |
          echo $GH_JOB_2_HTML_URL

          # Dynamic variable
          printenv "GH_JOB_"$GITHUB_JOB"_HTML_URL"

Private repos

If you want to use this in private repos, add the following permissions to your workflow job. See permission. (The action needs actions:read permission to access the job list. No need for public repo).

# ...
runs-on: ubuntu-latest
permissions:
  contents: read # default, for actions/checkout to work
  actions: read # <== read
# ...

LICENSE

AGPL-3.0 License

About

Expose JOB ID/URLs to the environment variables

Resources

License

Stars

Watchers

Forks

Packages

No packages published