Using a step of one job in `if` condition in another job


I am trying to understand how to write a workflow. Basically, what I want to do is:

  1. Run a job with an action called technote-space/get-diff-action. This saves the diffs in an environment variable called GIT_DIFF.
  2. After this I have five jobs that run tests. I only want to run these if: env.GIT_DIFF, but the environment variable is created in another job so I don’t know how to refer to it.

Any idea how I can do this?

This is a reference workflow.yaml file:

    runs-on: self-hosted
    name: Get git diff
      - uses: actions/checkout@v2
        name: Checkout this repository
      - uses: kartikdc/get-diff-action@5.0.0
        name: Get git diff
        id: get_git_diff
          PATTERNS: |

    if: jobs.get_git_diff.steps.get_git_diff.env.GIT_DIFF
    needs: cancel_previous_actions
    timeout-minutes: 10
    runs-on: [self-hosted]
    name: Run eslint check

Obviously this doesn’t work. Can someone tell me how I can achieve the desired result? Running the diff check in another job would be cool because there are multiple test jobs. Otherwise, I would have to add it as a step in all jobs.

Any help is appreciated. Thanks in advance.

Environment variables do not carry over between jobs. You can use job outputs to make data available from a job to others that have a needs dependency on it, see jobs.<job_id>.outputs.

1 Like

Thank you very much Luna

1 Like