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_ENV
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.