-1

This issue is reproducible. Simply paste the receivertest.yml in your GitHub workflow and you will see the error I m reporting.

Below is my caller workflow callertest.yml file:

---
name: Testcasecaller

on:
  workflow_dispatch

jobs:

  call-reusable-workflow:
    uses: knowyrtech/DevOps/.github/workflows/receivertest.yml@newmmtmp
    secrets: inherit 

Here is my called workflow receivertest.yml that uses strategy matrix on 2 self-hosted runners viz linuxrunner and winrunner:

---

name: refresh_poc - AD

env:
  linuxrunner: '0361'
  winrunner: '1567'

on:

  workflow_call:

    inputs:
      srcDBenv:
        description: 'Source Environment'
        required: false
        type: string
        default: 'STG'

    secrets:
      AUTOMATED_TOKEN:
        description: 'DevOps github repo secret'
        required: true 

jobs:

  SETVARS:
    name: Set variables

    outputs:
      formatdate: "${{ steps.get-date.outputs.formatdate }}"

    runs-on: ${{ linuxrunner }}

    steps:

      - name: Get present date
        id: get-date
        run: |
          date=$(date +"%d%b%Y")
          echo "formatdate=$date" >> $GITHUB_OUTPUT

 

  TAKING_PROD_DATABASE_BACKUP:
    name: Taking backup


    needs:
      - SETVARS

    runs-on: ${{ matrix.os }}

    strategy:
      max-parallel: 1    
      matrix:
        os: [${{ env.winrunner }}, ${{ env.linuxrunner }}]

    steps:

      - name: Checkout
        env:
          ATOTOKEN: ${{ secrets.AUTOMATED_TOKEN }}
        with:
          repository: knowyrtech/DevOps
          ref: newmmtmp
          path: DevOps
          sparse-checkout: |
            scripts
          sparse-checkout-cone-mode: false  
          token: ${{ env.ATOTOKEN }}

        if: matrix.os == ${{ env.winrunner }}

  

Error when action is run:

Invalid workflow file: .github/workflows/callertest.yml#L10

error parsing called workflow ".github/workflows/callertest.yml" -> knowyrtech/DevOps/.github/workflows/receivertest.yml@newmmtmp (source branch with sha:fdb50734f2e37ecaa1eaf469ebfcad75de3c1fb7) : You have an error in your yaml syntax on line 49

I tried os: [${{ winrunner }}, ${{ linuxrunner }}] but that too did not work.

The editor prompts an error as: missed comma between flow collection entries but as you can see the comma is very well there.

I tried setting the combined runners as outputs and feeding the outputs to the strategy matrix but then I get error Error when evaluating 'strategy' for job

  set-vars:
    runs-on: ubuntu-latest
    outputs:
      os-matrix: ${{ steps.set-vars.outputs.os-matrix }}
    steps:
      - name: Set matrix values
        id: set-vars
        run: |
          echo "os-matrix=${{ env.winrunner }},${{ env.linuxrunner }}" >> $GITHUB_OUTPUT

and

os: fromJson(${{ NEEDS.SET-VARS.OUTPUTS.OS-MATRIX }})

While troubleshooting the issue I also landed on syntax error for runs-on: ${{ linuxrunner }} or runs-on: ${{ env.linuxrunner }}

Can you please suggest what the issue is with my workflow code?

Ashar
  • 2,942
  • 10
  • 58
  • 122
  • Several attempts to get this work did not help. Can someone please suggest @Everyone – Ashar Aug 11 '23 at 05:46
  • tried `${{ env.linuxrunner }}`? – jessehouwing Aug 12 '23 at 14:26
  • Yes @jessehouwing, the primary issue is constructing the matrix but at times I get the `env.linuxrunner` error too. My requirement is the get the above workflow to work. – Ashar Aug 12 '23 at 14:52
  • As far as I can tell the `env` context isn't available when setting matrix values. I have an example how to pass the outputs of a previous job though: https://stackoverflow.com/questions/76183077/how-to-trigger-2nd-pipeline-after-completing-all-previous-multiple-pipelines-und/76183348#76183348 – jessehouwing Aug 12 '23 at 15:17
  • @jessehouwing I m well aware of passing `outputs` to matrix values. The issue in my case is passing `runners` defined as environment `.env` variables to matrix values. – Ashar Aug 12 '23 at 16:14
  • https://github.com/orgs/community/discussions/26388 – jessehouwing Aug 12 '23 at 16:59
  • @jessehouwing thank you for the github post and answer. But why is converting matrix `env. ` variables as `outputs` variable as shown in the second attempt/approach also not work? – Ashar Aug 13 '23 at 04:44
  • That second example doesn't look like valid json. It seems to be missing `[...]`. I find the syntax for passing variables super awkward (as you've already encountered), in the linked post I use `pwsh` to format the json correctly, makes things a lot easier. – jessehouwing Aug 13 '23 at 09:30
  • @jessehouwing In the second example i tried but could not construct acceptable json for runners. Can you please suggest? – Ashar Aug 14 '23 at 01:50
  • Check out https://stackoverflow.com/questions/76183077/how-to-trigger-2nd-pipeline-after-completing-all-previous-multiple-pipelines-und/76183348#76183348 – jessehouwing Aug 14 '23 at 07:59

0 Answers0