Get self-hosted runner name

Hi,

Is it possible to get the name of the runner on which a job is executed?

At the workflow yaml level or at the job / step level.

I have 4 bare metal servers on which I run container base tests.
Each bare metal has a set of static services… so that when a VM needs a shared service it can get it from the bare metal.

In the docs, I see there is only:

  • runner.os
  • runner.temp
  • runner.tool_cache

https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#runner-context

Technically, you could probably retrieve it from its own logs.

But practically, I’d just use hostname – that’s available on macOS, Linux, and Windows.

You could also probably add an extra environment variable.

Thanks for the reply.

I have this job.

The steps are executed inside the container… and I can’t see how to tell GitHub Action that I want a step to be executed on the docker-host / Ubuntu.

jobs:

  standard:

    name: Container
    container: ghcr.io/alpine/alpine:3.12
    runs-on: ubuntu-20.04
    timeout-minutes: 45
    steps:

    # Executed inside the container.
    - name: Alpine setup
      run: |
        apk update
        apk upgrade
        apk add shadow sudo bash git libffi

    # Executed inside the container.
    - uses: actions/checkout@v2
      with:
        clean: false

You could add another job get-hostname, run it before your current job (needs: standard), determine the hostname and set it as job output (Workflow syntax for GitHub Actions - GitHub Docs) and then use it in the steps that are executed in the container (${{ needs.get-hostname.outputs.<output-name> }}).

That second job might end up running on a different runner though, so it won’t reliably say which runner the container is on.

2 Likes

I ended up with this option:

Each docker-engine hosts bare-metal has a file with default container variables

/srv/docker/default.env

Inside that variable it can have the URL to various services

The /srv/docker/default.env file is managed outside of GitHub Actions/Workflow.

The workflow looks like this.

jobs:

  standard:

    name: Container
    container:
      image: ghcr.io/alpine/alpine:3.12
      options: --env-file /srv/docker/default.env
    runs-on: docker-host
    timeout-minutes: 45
    steps:

    # Executed inside the container.
    - name: Alpine setup
      run: |
        apk update
        apk upgrade
        apk add shadow sudo bash git libffi
        echo $DOCKER_ENGINE_HOST

    # Executed inside the container.
    - uses: actions/checkout@v2


I also implemented a simple rendevous service in which each container will access an URL like http://services.local/container-services and the page will return a list of service depending on the remote/source IP of the http client…

Basically this was a more complex version of what is my ip :slight_smile:

2 Likes

Oops, I forgot about that! Would giving each self-hosted runner a unique label and using the same machine for both jobs work? (Ideally choosing a random machine for the first job, and then picking the same for the second)

I don’t know about unique labels… looks complicated and I don’t understand how it works.


having the runner name in the GitHub context would have been perfect,
but the environment file works fine for this case and I am happy with this solution.