github-actionsgithub-actions-self-hosted-runners

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


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?


Solution

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

    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