skip to Main Content
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 ?

2

Answers


  1. Chosen as BEST ANSWER
    ${{ (inputs.shouldUseSelfHosted) && fromJSON('[ "self-hosted", "Linux", "X64" ]') || 'ubuntu-latest' }}
    

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


  2. #eg) for test branch => runs-on: ubuntu-latest
    for master branch => runs-on: [‘self-hosted’, ‘products’, ‘latest’]

    Complete workflow file will be looks like:

    ---
    
    name: test on multiple runners
    
    on:
      push:
        branches:
          - master
          - test
    
    jobs:
      simple-test:
        # if affected branch is 'test' then runs on 'ubuntu-latest' else self-hosted...
        runs-on: ${{ github.ref_name == 'test' && 'ubuntu-latest' || fromJSON('["self-hosted", "products", "latest"]') }}
        steps:
          - name: simple evaluation on test
            run: echo "runs"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search