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
echo "MY_OUTPUT=${{ steps.checkout_step.outcome }}" >> $env:GITHUB_ENVecho "MY_OUTPUT=${{ steps.checkout_step.outcome }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -AppendUsing 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.
                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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With