3

I want to access step outcome from previous job on my Windows self-hosted runner. In order to do so, I use output variables like below, which works just fine (printing "success" in the last step).

name: Debug workflow

on: workflow_dispatch
jobs:
  job1:
    runs-on: tester-1
    outputs:
      output1: ${{ steps.step1.outputs.MY_OUTPUT }}
    steps:
      - name: Checkout with submodules
        id: checkout_step
        uses: actions/checkout@v3
      - name: Write variable to output
        id: step1
        run: echo '::set-output name=MY_OUTPUT::${{ steps.checkout_step.outcome }}'
  job2:
    runs-on: tester-1
    needs: job1
    env:
      OUTPUT1: '${{needs.job1.outputs.output1}}'
    steps:
    - name: Print outputs from previous 
      run: echo ${{ env.OUTPUT1 }}

However ::set-output is deprecated so I would like to convert to correct approach. Based on another question, I've already tried replacing my echo '::set-output name=MY_OUTPUT::${{ steps.checkout_step.outcome }}' to

  1. echo "MY_OUTPUT=${{ steps.checkout_step.outcome }}" >> $env:GITHUB_ENV
  2. echo "MY_OUTPUT=${{ steps.checkout_step.outcome }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

Using either version results in an error from printing step and empty OUTPUT1 variable. What am I doing wrong?

Run echo 
  echo 
  shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'"
  env:
    OUTPUT1: 
Write-Output : Cannot process command because of one or more missing mandatory parameters: InputObject.
At C:\tester-1-runner\_work\_temp\a19d4f45-cf0e-4ddb-b62e-4f05a2f00461.ps1:2 char:1
+ echo
+ ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Write-Output], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingMandatoryParameter,Microsoft.PowerShell.Commands.WriteOutputCommand
 
Error: Process completed with exit code 1.
Compo
  • 36,585
  • 5
  • 27
  • 39
YogoWafel
  • 101
  • 2
  • 9

1 Answers1

6

You are mixing up outputs and environment variables.

The proper syntax for populating env vars with shell: bash is:

echo "foo=bar" >> $GITHUB_ENV

and for outputs:

echo "foo=bar" >> $GITHUB_OUTPUT

As you're using a Windows runner, your solution should be with $ENV:GITHUB_OUTPUT:

run: echo "MY_OUTPUT=${{ steps.checkout_step.outcome }}" >> $ENV:GITHUB_OUTPUT

After that, the echo should work fine:

echo ${{ env.OUTPUT1 }}

or,

echo $ENV:OUTPUT1

See these threads for more details:

Azeem
  • 11,148
  • 4
  • 27
  • 40
aknosis
  • 3,602
  • 20
  • 33