function in runs-on doesn't work
Describe the bug
I have the workflow listen on event deployment for app deployment.
I'd like to reuse the same workflow for both nonprod and prod.
that means i have to use variable as runner label in runs-on statement.
however, runs-on doesn't support func call:
Not work
runs-on: ["${{ fromJson(github.event.deployment.payload).runnerLabel }}"] results in runs-on: [""]
Work
runs-on: ["${{ github.event.deployment.description }}"] results in runs-on: ["prod"]
assume description has the right runner label value
To Reproduce Steps to reproduce the behavior:
name: CD
on: ['deployment']
jobs:
deploy:
name: Deploy
runs-on: ["${{ fromJson(github.event.deployment.payload).runnerLabel }}"]
steps:
...
the workflow failed says no runner matched. "${{ fromJson(github.event.deployment.payload).runnerLabel }}" results in an empty string.
Expected behavior
expect the value being correctly extracted from json, like runs-on: ["prod"]
Runner Version and Platform
Version of your runner?
2.273.5
OS of the machine running the runner? OSX/Windows/Linux/...
Ubuntu 20.04
What's not working?
Please include error messages and screenshots.
Job Log Output
N/A
Runner and Worker's Diagnostic Logs
N/A
@missedone did you send any payload to the deployment, since ${{ fromJson(github.event.deployment.payload).runnerLabel }} resolved to empty string?
Yes, the payload does contain field “runnerLabel”
@missedone
Oh, just do ${{ github.event.deployment.payload.runnerLabel }}, the github.event is already a JSON.
nope, i tried the above, got error:
Error when evaluating 'runs-on' for job 'deploy'. (Line: 8, Col: 30): Unexpected value ''
my workflow looks like
name: CD
on: ['deployment']
jobs:
deploy:
name: Deploy
runs-on: [linux, "${{ github.event.deployment.payload.runnerLabel }}"]
@missedone that means github.event.deployment.payload.runnerLabel is empty.
Can you verify whether it set by adding the following (make the run runs-on to run any label for this testing)?
- run: |
echo ${{toJSON(github.event.deployment.payload)}}
yes, the field is in the payload:

on: ['deployment']
jobs:
deploy:
name: Deploy
runs-on: [linux, "${{ github.event.deployment.task }}"]
steps:
- name: dump deployment payload
run: |
echo ${{toJSON(github.event.deployment.payload)}}
@missedone can you add a repo-level secret ACTIONS_STEP_DEBUG=true to enabled debug log for workflow runs within the repository, and then run a job that has:
- run: |
echo ${{github.event.deployment.payload.runnerLabel}}
to see whether the runner can get the right value.
you might want to remove the secret after testing.
https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging
@TingluoHuang , as mentioned, i used the expression at runs-on field
name: CD
on: ['deployment']
jobs:
deploy:
name: Deploy
runs-on: [Linux, "${{github.event.deployment.payload.runnerLabel}}"]

the above debugging tip won't work since it already failed earlier on getting the right runner.
BTW, as you know github.event.deployment.payload can be any string, Ex. plain text, json, yaml, etc.
in my case, i use json for structural payload data, so you can tell the difference from the output of the following snippet:
steps:
- run: |
echo payload.runnerLabel: ${{github.event.deployment.payload.runnerLabel}}
echo fromJson ${{ fromJson(github.event.deployment.payload).runnerLabel }}
output:
Run echo payload.runnerLabel:
echo payload.runnerLabel:
echo fromJson nonprod
shell: /usr/bin/bash -e {0}
payload.runnerLabel:
fromJson nonprod
so that's why i said I have to use func fromJson on field runs-on, but it doesn't work:
runs-on: ["${{ fromJson(github.event.deployment.payload).runnerLabel }}"]
@nikola-jokic I'm seeing this as well for blocks like
jobs:
clean:
needs:
- bootstrap
runs-on: [ self-hosted, "${{ inputs.machine }}" ]
steps:
...
The odd part is that the issue is predictably intermittent: if I re-run the failed job it will succeed without warnings.