I am currently trying to create some dynamic workflow files so I can deploy to different self-hosted runners using the environment variable system. I follow the work around in this post: Specify runner to be used depending on condition in a GitHub Actions workflow
The idea is to use a step to generate output where you get the variable from the selected environment to be used in a steps 'runs-on:' setting. Currently this is my workflow file, with removed stuff for simplicity:
name: Dashboard - Publish and deploy
on:
workflow_dispatch:
inputs:
environment:
type: environment
description: Select the environment
buildConfiguration:
<removed for simplicity>
jobs:
setup:
name: Setup runner labels for deploy
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs:
deployrunner: ${{ steps.step1.outputs.deployrunner }}
steps:
- name: Set runs-on for deploy
id: step1
run: |
echo "deployrunner=${{ vars.DEPLOYSERVER }}" >> $GITHUB_OUTPUT
build:
<removed for simplicity>
deployDashboard:
needs: [build, setup]
runs-on: ${{needs.setup.outputs.deployrunner}}
name: Deploy dashboard to server
environment: ${{ inputs.environment }}
env:
ServiceBaseDir: ${{ vars.DASHBOARD_DIR }}
steps:
<removed for simplicity>
The problem is that this does not seem to work. If I exchange the runs-on: ${{needs.setup.outputs.deployrunner}
to runs-on: [self-hosted,dev1]
the runner on dev1 will see it and start up:
> Requested labels: self-hosted, dev1
> Job defined at: <redacted>/.github/workflows/<redacted>
> Waiting for a runner to pick up this job...
> Job is about to start running on the runner: dev1 (repository) <-- job started
But when I use the output variable, I can see that the labels are correctly applied but the runner never sees it:
> Requested labels: self-hosted, dev1
> Job defined at: <redacted>/.github/workflows/<redacted>
> Waiting for a runner to pick up this job...
And it continues to wait. If I then switch back to the explicit runs-on notation, it works again.
I have tried to restart the dev1 server and/or restart the runner, but to no effect. In the environment variable, the vars.DEPLOYSERVER
variable is set to self-hosted, dev1
but I have also tried [self-hosted, dev1]
with no change. The runners version is 2.301.1, which is only one version behind. Checked the release notes (https://github.com/actions/runner/releases) and the changes does not indicate any changes related to this.
Anyone know if this is a know bug for self-hosted runners that I could not find or knows what is going on here?
Update 2023-03-06
I was building a bug report when I found out that this trick does work on local runners. It does not work, however, if you use multiple labels. If you use self-hosted, dev1
the local runner will not work. But if you only supply dev1
it does work. Its not possible at the moment to add the variable inside brackets of the runs-on, as the workflow parser sees this as an error.