Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Action add "needs" with separate workflow file

I have got two workflows:

  • workflow1.yaml
  • workflow2.yaml

I need in workflow2.yaml add something like:

jobs:
  build_kotlin:
    runs-on: [server1, server2, server3]
    needs: [workflow1]
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

Currently "needs" doesn't work properly. How can reference separate workflow yaml file?

like image 528
debek Avatar asked Nov 30 '25 19:11

debek


1 Answers

needs is only used to establish relationships between jobs -- not entire workflows.

If you want to run "workflow2.yaml" after "workflow1.yaml" has been completed, then add a trigger like so:

on:
  workflow_run:
    workflows: [workflow1]
    types:
      - completed

jobs:
  build_kotlin
    # ...

Read more on Events That Trigger Workflows

Alternatively, you could make workflow1 a reusable workflow and then make sure it is executed before workflow2 like so:

jobs:
  workflow1:
    uses: octo-org/example-repo/.github/workflows/workflow1.yaml@main

  build_kotlin:
    runs-on: [server1, server2, server3]
    needs: [workflow1]
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

like image 200
rethab Avatar answered Dec 06 '25 16:12

rethab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!