0

I have a powershell that returns key=value like the below:

cat C:\Logs\getallkey.ps1

Write-Host "app_name=Signup-qa"

Here is the github actions:

  - name: Sample append to OUT
    id: sample
    run: |
      echo "app_name_sample=worksss" >> $env:GITHUB_OUTPUT
      
  - name: Use sample script output
    run: |
      echo "Sample Application_Name: ${{ steps.sample.outputs.app_name_sample }}"  

  - name: Run  PowerShell script
    id: run-script
    run: |
      & "C:\Logs\getallkey.ps1"
      
  - name: Assign to variable
    id: run-scriptx
    run: |
      $returnvalue=& "C:\Logs\getallkey.ps1"
      echo "$returnvalue" >> $GITHUB_OUTPUT
     
  - name: Use script output
    run: |
      echo "Application Name: ${{ steps.run-scriptx.outputs.app_name }}"

See output below:

enter image description here

As evident from the output, Use sample script output step worked when similar step Use script output did not print the output. The below is printed in steps Assign to variable

app_name=Signup-qa

However, the same is not being set and printed for step Use script output which I tried to by means of echo "$returnvalue" >> $GITHUB_OUTPUT which I thought should have translated to echo "app_name=Signup-qa" >> $GITHUB_OUTPUT and thus should have printed for step Use script output as desired output, however it does not:

Application Name: Signup-qa

I also tried the below but it too did not help.

  - name: Assign to variable
    id: run-scriptx
    run: |
      $returnvalue=& "C:\Logs\getallkey.ps1"
      echo "$returnvalue" >> $env:GITHUB_OUTPUT

Can you please assist?

Ashar
  • 2,942
  • 10
  • 58
  • 122
  • Typo: missing `app_name` while setting the output parameter. – Azeem May 22 '23 at 04:33
  • Does this answer your question? [Value not set using $GITHUB\_OUTPUT](https://stackoverflow.com/questions/74443940/value-not-set-using-github-output) – Azeem May 22 '23 at 04:33
  • @Azeem how am i missing `app_name`? here -> `echo "$returnvalue" >> $GITHUB_OUTPUT` should translate to `echo "app_name=Signup-qa" >> $GITHUB_OUTPUT` and that's how `app_name` should be set alright in the output parameter? – Ashar May 22 '23 at 05:09
  • Here is my workflow file: https://github.com/knowyrtech/actions_param/blob/main/.github/workflows/blank.yml. I cannot use shell `bash` and rest options I tried and mentioned in my original post https://stackoverflow.com/questions/74443940/value-not-set-using-github-output – Ashar May 22 '23 at 05:15
  • I missed that. That's fine if you're using it like that. However, with default Powershell, you need to use `"$returnvalue" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append`. – Azeem May 22 '23 at 05:17
  • tried the suggestion `"$returnvalue" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append` here `https://github.com/knowyrtech/actions_param/blob/main/.github/workflows/blank.yml` but the output still does not print the variable `app_name`. Output here: `https://github.com/knowyrtech/actions_param/actions/runs/5042132396/jobs/9042458293` – Ashar May 22 '23 at 05:25
  • @Azeem Updated my post with added sample output here https://github.com/knowyrtech/actions_param/blob/main/.github/workflows/blank.yml. the output append seems to be working when the variable is set manually but does not work when it is returned as variable from powershell ps1 file. Can you please check / suggest? – Ashar May 22 '23 at 05:48
  • What is the ouptut of `echo $returnvalue`? Which command is now working? BTW, you're using a self-hosted runner. What kind of Windows is that? – Azeem May 22 '23 at 06:21
  • Is [this](https://github.com/knowyrtech/actions_param/blob/main/.github/workflows/blank.yml#L38) not working? – Azeem May 22 '23 at 06:22
  • @Azeem no probably becoz it's returned by powershell. Can u please check – Ashar May 22 '23 at 06:30
  • @Azeem yes, it's a windows 10 runner – Ashar May 22 '23 at 06:31
  • Apparently, all those commands look fine and should work. Looks like it may be something to do with the script itself or the runner but it's not obvious. Please write a sample test script returning different strings with and without `=` and try to set those as outputs. – Azeem May 22 '23 at 06:55

0 Answers0