runner icon indicating copy to clipboard operation
runner copied to clipboard

function in runs-on doesn't work

Open missedone opened this issue 5 years ago • 10 comments

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 avatar Oct 30 '20 22:10 missedone

@missedone did you send any payload to the deployment, since ${{ fromJson(github.event.deployment.payload).runnerLabel }} resolved to empty string?

TingluoHuang avatar Apr 22 '21 22:04 TingluoHuang

Yes, the payload does contain field “runnerLabel”

missedone avatar Apr 23 '21 02:04 missedone

@missedone Oh, just do ${{ github.event.deployment.payload.runnerLabel }}, the github.event is already a JSON.

TingluoHuang avatar Apr 23 '21 02:04 TingluoHuang

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 avatar Apr 23 '21 02:04 missedone

@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)}}

TingluoHuang avatar Apr 23 '21 03:04 TingluoHuang

yes, the field is in the payload:

image

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 avatar Apr 23 '21 04:04 missedone

@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 avatar Apr 24 '21 02:04 TingluoHuang

@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}}"]

image

the above debugging tip won't work since it already failed earlier on getting the right runner.

missedone avatar Apr 26 '21 22:04 missedone

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 }}"]

missedone avatar Apr 26 '21 22:04 missedone

@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.

brianthelion avatar Dec 02 '22 16:12 brianthelion