Search code examples
github-actionsgithub-actions-self-hosted-runners

How to Dynamically assign the runs-on value in the github actions


name: test if conditions
name: test if conditions
on:
  push:
    branches: [master, test]
env:
  TEST_BRANCH: "test"
  EMPTY_VALUE: ""
jobs:
  test-conditions:
    runs-on: ubuntu-latest
    steps:
      - name: simple evaluation on test
        run: echo "runs"
#eg) for test branch => runs-on: ubuntu-latest
     for master branch => runs-on: ['self-hosted', 'products', 'latest']

is it possible to dynamically load the runs-on in the same workflow ?


Solution

  • ${{ (inputs.shouldUseSelfHosted) && fromJSON('[ "self-hosted", "Linux", "X64" ]') || 'ubuntu-latest' }}
    

    Reference: https://github.com/actions/runner/issues/409