在github.actions中创建拉取请求时运行特定作业

时间:2020-07-02 08:11:53

标签: github automation continuous-integration continuous-deployment github-actions

我已经使用GitHub动作实现了ci / cd。在ci / cd中,当我要释放标签时,我要构建三个作业,当我向特定分支提出拉取请求时,出于健康检查的目的,应仅执行两个作业。例如,我有一个功能分支,我想将此功能分支合并到devel分支。当我提高公关时,应该只运行两个工作。我该如何实现?下面是我的示例代码。

name: CI

on:
  pull_request:
    branches:
      - master
      - devel
  push:
    tags:
      - '*'
jobs:
  build:
    name: build
    runs-on: self-hosted
    steps:
       --------------
   deploy:
    name: deploy
    runs-on: self-hosted
    steps:
      ------------
   automation-test:
     name: test
     runs-on: self-hosted
     steps:
       ------------
 

在这里提出公关时,我要运行构建和自动化测试作业。

1 个答案:

答案 0 :(得分:1)

您在这里有两个选择:

  1. 具有为正确的分支运行的单独的工作流文件。
  2. 在工作中使用条件条件

第一个选项可能是您想要的那个。唯一的问题是,一个作业的输出是否用于另一作业,但这听起来不像您这样。我建议您将yaml工作流程分为两个单独的工作流程:

name: CI

on:
  pull_request:
    branches:
      - master
  push:
    tags:
      - '*'
jobs:
  build:
    name: build
    runs-on: self-hosted
    steps:
       --------------
   deploy:
    name: deploy
    runs-on: self-hosted
    steps:
      ------------
   automation-test:
     name: test
     runs-on: self-hosted
     steps:
       ------------
name: PR Builder

on:
  pull_request:
    branches:
      - devel
jobs:
    whatever_testing_jobs_you_like:

第二个选项可能看起来像这样:

name: CI

on:
  pull_request:
    branches:
      - master
  push:
    tags:
      - '*'
jobs:
  build:
    name: build
    runs-on: self-hosted
    steps:
       --------------
   deploy:
    if: "github.ref != devel" # you might tweak the condition based on your needs
    name: deploy
    runs-on: self-hosted
    steps:
      ------------
   automation-test:
     name: test
     runs-on: self-hosted
     steps:
       ------------

这些上下文值/条件为well documented