0

I want to pass a value from a job to another. The output will be a precondition for the next job so if the value will be false the next job will not run.

I've seen that there is a solution for this with ::set-output, but this feature will be deprecated.

I want to achieve something like this:

jobs:
  check-version:
    runs-on: ubuntu-latest
    steps:
        if: ${{ condition }}
        run: |
          echo "::set-output name=CONTINUE::false"

  deploy:
    if: ${{ needs.check-version.outputs.CONTINUE != 'false' }}
    needs: [check-version]
    runs-on: ubuntu-latest
    steps:
      - run: echo "The job is running"
Valentin
  • 1,159
  • 1
  • 11
  • 22
  • 1
    See [setting an output parameter](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter) and [defining outputs for jobs](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs). – Azeem May 30 '23 at 05:46
  • 1
    What have you tried? What prevents you doing it as documented? Please read the announcement **[GitHub Actions: Deprecating save-state and set-output commands](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/)** and follow the instructions to handle the deprecation (also do what @Azeem wrote). – hakre May 30 '23 at 05:48
  • I've also tried to set it as an output parameter but I get: `Unrecognized named-value: 'steps'. Located at position 1 within expression: steps.check-version.outputs.CONTINUE`. – Valentin May 30 '23 at 05:55
  • @Valentin: Double check with the documentation, the diagnostic message tells you where the error is and what went wrong.Or in short: read the resources Azeem linked to learn how it is done (`id` **!!**, `outputs` **!!**, `needs` **!!**, the documentation has a whole "learn" section as well if you're new to Microsoft Github Actions). – hakre May 30 '23 at 06:16
  • 1
    You need to first define outputs for job. Reference [Defining outputs for jobs](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs) – Haridarshan May 30 '23 at 10:03

1 Answers1

1

According to all the references shared with you in the comments:

Your workflow should look like this:

jobs:
  check-version:
    runs-on: ubuntu-latest
    outputs:
      continue: ${{ steps.check.outputs.continue }}
    steps:
      - name: Check Version step
        if: ${{ condition }}
        id: check
        run: echo "continue=false" >> $GITHUB_OUTPUT

  deploy:
    needs: [check-version]
    if: ${{ needs.check-version.outputs.continue != 'false' }}
    runs-on: ubuntu-latest
    steps:
      - run: echo "The job is running"
GuiFalourd
  • 15,523
  • 8
  • 44
  • 71