0

Harded code value app_name was here and it worked fine -> app_namexx: ${{ steps.run-script.outputs.app_name }}

I now wish to replace hard coded app_name to input variable key_name. So, Tried the below but I get error:

name: CALLER main yml

on:
  push:
    branches: main
  workflow_dispatch:  
    
    inputs:
      key_name:
        required: true
        default: 'app_name'
   
jobs:
  mainjob1:
    runs-on: "windows-latest"
    
    outputs:
      app_namexx: ${{ steps.run-script.outputs.[key_name] }}  

    steps:        
      - name: Checkout  repository
        uses: actions/checkout@v3

Error output:

The workflow is not valid. Error from called workflow. Unrecognized named-value: 'key_name'. Located at position 27 with expression: steps.run-script.outputs[key_name]

I tried the following but none of it works:

app_namexx: ${{ steps.run-script.outputs[key_name] }}
app_namexx: ${{ steps.run-script.outputs[$key_name] }}
app_namexx: ${{ steps.run-script.outputs.$key_name }}
app_namexx: ${{ steps.run-script.outputs.${key_name} }}
app_namexx: ${{ steps.run-script.outputs.${ inputs.key_name } }} 

The purpose of variabelizing outputs is every time a new key_name is passed the reusable workflow will return a different value for that key_name by parsing an key-value style XML using PowerShell. Below are a few sample snapshots of different key-name to powershell script and the output returned. If key_name is blank then it will return all key-value pairs:

enter image description here

Thus, based upon the inputs.key_name passed by the user or if kept empty the caller workflow should get the value returned by the reusable workflow.

I may have to share a new post when dealing with return value for all key-values returned in case -key_name is empty ""

Ashar
  • 2,942
  • 10
  • 58
  • 122
  • You would also need to update the output name when setting it using `echo "${{inputs.key_name}}" >> $env:GITHUB_OUTPUT`. Is there a reason why the step output name has to be dynamic? Because the `mainjob1` output name will still be `app_namexx` anyway, so I wonder what you will gain by making this change. – GuiFalourd May 23 '23 at 11:31
  • @GuiFalourd i could not understand the solution you are proposing as you have not touched upon `outputs: app_namexx: ${{ steps.run-script.outputs.[key_name] }}` The dynamic `key_name` helps fetch dynamic values from a (XML)file so `app_namexx` will get different values for different `key_name` passed to this reusable workflow. – Ashar May 23 '23 at 11:37
  • I wasn't suggesting an answer yet :) Just getting more context and informing the dynamic input value should be used somewhere else in the workflow as well here to set the output. I'll make some tests here now that I get what you want to achieve. – GuiFalourd May 23 '23 at 11:39
  • 1
    @GuiFalourd i have updated the original post with a brief explanation of the need and what I m trying to achieve. – Ashar May 23 '23 at 11:47
  • It seems the following syntax is accepted by the Github interpreter: `app_namexx: ${{ steps.run-script.outputs.inputs.key_name}}` however it doesn't seem to be setting the output variable as expected (it also works with `app_namexx: ${{ steps.run-script.outputs.env.key_name}}` if using env variables at the workflow level). I'm making some tests [here](https://github.com/GuillaumeFalourd/poc-github-actions/actions/workflows/workflow-tester81.yml) using this [workflow config](https://github.com/GuillaumeFalourd/poc-github-actions/blob/main/.github/workflows/workflow-tester81.yml). – GuiFalourd May 23 '23 at 12:00
  • @GuiFalourd this is a reusable template so it ought to be `inputs` and not `env.key_name` please correct me if that is not the case. – Ashar May 23 '23 at 12:44
  • You can set the inputs as env variable in any workflow to use them in steps operations. What you can't do is shared the whole env context from the main workflow to a reusable one. – GuiFalourd May 23 '23 at 13:29
  • @GuiFalourd please let me know where you tested this so I can have a look / leverage -> `You can set the inputs as env variable` – Ashar May 23 '23 at 13:38
  • It was in this commit: https://github.com/GuillaumeFalourd/poc-github-actions/blob/69e313c0e69e19dc76041c11e1bdbd55d6869c9d/.github/workflows/workflow-tester81.yml – GuiFalourd May 23 '23 at 14:05

0 Answers0