admin管理员组

文章数量:1397110

I have the following 2 jobs. I have confirmed that the assignment to the variables in each step of the Set batch indicator job is valid and was able to echo out what I expected. However when I try to set it to the GITHUB_OUTPUT to refer in the 2nd step, it doesn't seem to work. The self hosted runner is on Windows 2022 and I need to use powershell for the shell (not powershell core, shell:pwsh). I have tried the below implementation of setting to GITHUB_OUTPUT as well as echo "variable=$variable" >> GITHUB_OUTPUT and echo "variable=$variable" >> env:GITHUB_OUTPUT I have tried them both with and without quotations around the GITHUB_OUTPUT

set-batch-indicator:
    runs-on: self-hosted   
    environment: ${{inputs.environment}}
    needs: [build, test] 
    steps:    
    - name: Set Config Source Batch Identifier
      id: batch-config-source
      run: |
        $ConfigSrcBatch = "${{ vars.CODE_SOURCE_BATCH }}".replace("BATCH","${{ inputs.batchToDeploy }}") 
        echo "ConfigSourceBatch=$ConfigSourceBatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
      shell: powershell
    - name: Set Config Target Batch Identifier
      id: batch-config-target
      run: |
        $ConfigTrgtBatch = "${{ vars.CONFIG_SOURCE_BATCH }}".replace("BATCH","${{ inputs.batchToDeploy }}")
        echo "ConfigTargetBatch=$ConfigTargetBatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
      shell: powershell
    - name: Set Code Source Batch Identifier
      id: batch-code-source
      run: |
        $CodeSourceBatch = "${{ vars.CONFIG_TARGET_BATCH }}".replace("BATCH","${{ inputs.batchToDeploy }}")
        echo "CodeSourceBatch=$CodeSourceBatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
      shell: powershell
    - name: Set Distribution Path Batch Identifier
      id: batch-dist-path
      run: |        
        $DistributionPathBatch = "${{ vars.DISTRIBUTION_PATH_BATCH }}".replace("BATCH","${{ inputs.batchToDeploy }}")
        echo "DistributionPathBatch=$DistributionPathBatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
        echo "Test='t'" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
      shell: powershell
    - name: Debug GITHUB_OUTPUT
      run: |
        Get-Content $env:GITHUB_OUTPUT
      shell: powershell
  stage:
    runs-on: self-hosted   
    environment: ${{inputs.environment}}
    needs: [build, test, set-batch-indicator]     
    steps:    
    - name: Debug GITHUB_OUTPUT
      run: |
        Get-Content $env:GITHUB_OUTPUT
      shell: powershell
    - name: Confirm Batch Identifier insertion
      run: |
        echo ${{ needs.set-batch-indicator.outputs.ConfigSourceBatch }}
        echo ${{ needs.set-batch-indicator.outputs.ConfigTargetBatch }}
        echo ${{ needs.set-batch-indicator.outputs.CodeSourceBatch }}
        echo ${{ needs.set-batch-indicator.outputs.DistributionPathBatch }}

I tried to debug this a bit with get-content but the output is just empty. Even with my echo "Test='t'" line it is empty which makes no sense to me.

I have the following 2 jobs. I have confirmed that the assignment to the variables in each step of the Set batch indicator job is valid and was able to echo out what I expected. However when I try to set it to the GITHUB_OUTPUT to refer in the 2nd step, it doesn't seem to work. The self hosted runner is on Windows 2022 and I need to use powershell for the shell (not powershell core, shell:pwsh). I have tried the below implementation of setting to GITHUB_OUTPUT as well as echo "variable=$variable" >> GITHUB_OUTPUT and echo "variable=$variable" >> env:GITHUB_OUTPUT I have tried them both with and without quotations around the GITHUB_OUTPUT

set-batch-indicator:
    runs-on: self-hosted   
    environment: ${{inputs.environment}}
    needs: [build, test] 
    steps:    
    - name: Set Config Source Batch Identifier
      id: batch-config-source
      run: |
        $ConfigSrcBatch = "${{ vars.CODE_SOURCE_BATCH }}".replace("BATCH","${{ inputs.batchToDeploy }}") 
        echo "ConfigSourceBatch=$ConfigSourceBatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
      shell: powershell
    - name: Set Config Target Batch Identifier
      id: batch-config-target
      run: |
        $ConfigTrgtBatch = "${{ vars.CONFIG_SOURCE_BATCH }}".replace("BATCH","${{ inputs.batchToDeploy }}")
        echo "ConfigTargetBatch=$ConfigTargetBatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
      shell: powershell
    - name: Set Code Source Batch Identifier
      id: batch-code-source
      run: |
        $CodeSourceBatch = "${{ vars.CONFIG_TARGET_BATCH }}".replace("BATCH","${{ inputs.batchToDeploy }}")
        echo "CodeSourceBatch=$CodeSourceBatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
      shell: powershell
    - name: Set Distribution Path Batch Identifier
      id: batch-dist-path
      run: |        
        $DistributionPathBatch = "${{ vars.DISTRIBUTION_PATH_BATCH }}".replace("BATCH","${{ inputs.batchToDeploy }}")
        echo "DistributionPathBatch=$DistributionPathBatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
        echo "Test='t'" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
      shell: powershell
    - name: Debug GITHUB_OUTPUT
      run: |
        Get-Content $env:GITHUB_OUTPUT
      shell: powershell
  stage:
    runs-on: self-hosted   
    environment: ${{inputs.environment}}
    needs: [build, test, set-batch-indicator]     
    steps:    
    - name: Debug GITHUB_OUTPUT
      run: |
        Get-Content $env:GITHUB_OUTPUT
      shell: powershell
    - name: Confirm Batch Identifier insertion
      run: |
        echo ${{ needs.set-batch-indicator.outputs.ConfigSourceBatch }}
        echo ${{ needs.set-batch-indicator.outputs.ConfigTargetBatch }}
        echo ${{ needs.set-batch-indicator.outputs.CodeSourceBatch }}
        echo ${{ needs.set-batch-indicator.outputs.DistributionPathBatch }}

I tried to debug this a bit with get-content but the output is just empty. Even with my echo "Test='t'" line it is empty which makes no sense to me.

Share Improve this question edited Mar 27 at 19:36 jonrsharpe 122k30 gold badges268 silver badges475 bronze badges asked Mar 26 at 17:41 Madhu mMadhu m 1
Add a comment  | 

1 Answer 1

Reset to default 0

You have to set outputs at the job level:

set-batch-indicator:
  runs-on: self-hosted
  environment: ${{ inputs.environment }}
  needs: [build, test]
  outputs:
    ConfigSourceBatch: ${{ steps.batch-config-source.outputs.ConfigSourceBatch }}
    # etc.    
  steps:
    - # ...

Also, the PowerShell syntax to set an output, according to the docs, is this:

"SELECTED_COLOR=green" >> $env:GITHUB_OUTPUT

本文标签: powershellWorkflow outputs not being saved or readStack Overflow