GitHub操作:在工作流之间共享/引用作业

GitHub操作:在工作流之间共享/引用作业,github,continuous-integration,devops,continuous-deployment,github-actions,Github,Continuous Integration,Devops,Continuous Deployment,Github Actions,如前所述,在GitHub操作中,有一种很好的方法可以使用need关键字在其他jobs中引用jobs,例如 name: Share data between jobs on: [push] jobs: job_1: name: Add 3 and 7 runs-on: ubuntu-latest steps: # Steps job_2: name: Multiply by 9 needs: job_1 # The res

如前所述,在GitHub操作中,有一种很好的方法可以使用
need
关键字在其他
job
s中引用
job
s,例如

name: Share data between jobs
on: [push]

jobs:
  job_1:
    name: Add 3 and 7
    runs-on: ubuntu-latest
    steps:
        # Steps

  job_2:
    name: Multiply by 9
    needs: job_1
    # The rest of the job
我在文档中找不到答案的问题是:是否有方法在其他工作流中引用/共享
job
s?(即分开
yml
文件)


我的项目由几个独立的工作流组成,每个工作流都需要执行相同的初始
步骤。我试图避免在不同的
工作流
之间复制粘贴相同的步骤。

目前,我认为不可能指定工作流之间的依赖关系。本GitHub社区论坛讨论了这一点:

您可以使用相同的工作流文件,然后使用条件触发或不触发特定作业

如果您只想在有“推送到主”分支时运行作业,可以这样做:


谢谢我对你的答案进行了编辑,以包含讨论中投票最多的答案,因为我认为在大多数情况下,这实际上是一个很好的选择。
   deploy:
       if: github.event_name == 'push' && github.ref == 'refs/heads/master'