In a GitHub Actions workflow, how can you determine the Organziation where the current repository is housed?
Asked Answered
F

1

7

I'm trying to organize my workflow artifacts (on a self-hosted runner) using a structure similar to this:

c:\github\artifacts\{org}\{repo}\{runid}

Different organizations in our enterprise COULD have a repository with the same name, so I wanted to be able to organize by organization name.

I have this so far:

c:\github\artifacts\{org}\{${{ github.event.repository.name }}\${{ github.run_id }}\

How can I determine the organization name?

Fluorite answered 13/1, 2022 at 16:52 Comment(1)
Try github.event.repository.full_name which gives you both the org and repository name or github.event.repository.owner.name which is just the org.Trichinopoly
C
14

You can get that from github context. The repo name and the repository organization can be found with:

  • ${{ github.repository }} (repo name)
  • ${{ github.repository_owner }} (repo organization)

If you don't know what are the values and which env variables are available to runner, you can just run env in a step to print it out, like so:

name: Print environment variables

on:
  workflow_dispatch:

jobs:
  debug:
    runs-on: ubuntu-latest

    steps:
      - name: Print
        run: env | sort
Courtroom answered 14/1, 2022 at 10:57 Comment(1)
${{ github.repository_owner }} did it, thanksFluorite

© 2022 - 2025 — McMap. All rights reserved.