I can't pass variables between two seperate jobs on a windows based runner

60 Views Asked by At

so I am working on creating this workflow to check a website availability (production application) and then pass the result from this check to another job so that it could send a Teams notification for the team to let them know if something goes wrong.

What I intend to do is a simple curl request (Invoke-WebRequest) on a URL and pass the result to the second job and here is how I tried to do so (only one of 100s of attempts):

name: Website Availability Check

on:
  push:
    branches:
      - '*'
      
jobs:
  website_check:
    runs-on: [self-hosted, Windows]
    outputs:
      prod: ${{ steps.prod_check_step.outputs.prod }}
    steps:
      - name: Check Prod Website Availability
        id: prod_check_step
        run: |
          $website_url = "https://MY-WEBSITE.EXAMPLE/"
          $response = Invoke-WebRequest -Uri $website_url -Method GET -UseBasicParsing
          if($response.StatusCode -eq 200) {
            echo "Website is up $($response.StatusCode)"
            } else {
            echo "Website is down $($response.StatusCode)"
            }
          echo "prod=${ response.StatusCode }" >> $GITHUB_OUTPUT
          
  check_status:
    runs-on: ubuntu-latest
    needs: website_check
    steps:
      - name: Retrieve Prod Output
        run: |
          echo "Prod status is: ${{ needs.website_check.outputs.prod }}"

The result that I am getting from the first job in this workflow is this:

Check Prod Website Availability
Run $website_url = "https://MY-WEBSITE.EXAMPLE/"
Website is up 200

However, on the second job I only see this:

Retrieve Prod Output
Run echo "Prod status is: "
Prod status is: 

I already went through these references:

Use environment variable in github action if

I even tried this example from Defining outputs for jobs:

name: ENV Test

on:
  push:
    branches:
      - '*'

jobs:
  job1:
    runs-on: [Windows]
    # Map a step output to a job output
    outputs:
      output1: ${{ steps.step1.outputs.test }}
      output2: ${{ steps.step2.outputs.test }}
    steps:
      - id: step1
        run: echo "test=hello" >> "$GITHUB_OUTPUT"
      - id: step2
        run: echo "test=world" >> "$GITHUB_OUTPUT"
  job2:
    runs-on: ubuntu-latest
    needs: job1
    steps:
      - env:
          OUTPUT1: ${{needs.job1.outputs.output1}}
          OUTPUT2: ${{needs.job1.outputs.output2}}
        run: echo "$OUTPUT1 $OUTPUT2"

When I have the runs-on: set for ubuntu-latest I get the following result: Result from ubuntu-latest runner

But the second I switch to [Windows] (which is my self hosted runner) I get this result: Result from [Windows] runner

Any help would be appreciated, I've been stuck on this for the whole I really have no idea what else to try..

0

There are 0 best solutions below