1

paths: 'frontend/**'在单个 repo 中,我想为不同的路径 [和]创建多个触发器,并paths: 'backend/**'为(相同的)构建作业使用不同的参数。以下是两个工作流程。

name: Trigger Jenkins Build [ Build-Portal ]
on:
  push:
    branches: [ develop ]
    paths: 'frontend/**'
    types: [closed]
jobs:
  build:
    name: Triggering Jenkins Build [ Build-Portal ]
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
    - name: Trigger Build-Portal
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "UI":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...

name: Trigger Jenkins Build [ Build-Portal ]
on:
  push:
    branches: [ develop ]
    paths: 'backend/**'
    types: [closed]
jobs:
  build:
    name: Triggering Jenkins Build [ Build-Portal ]
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
    - name: Trigger Build-Portal
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "API":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...

我可以将这两个文件合并到一个工作流文件 ( .github/workflows/) 中,还是需要为每个文件创建单独的文件?

注意job_params两个触发器不同。

4

1 回答 1

3

根据github 操作文档,它应该使用多个路径在相同的工作流程中工作。

如果您还使用paths-filter 操作,您可以通过以下方式获得所需的结果:

例子:

name: Trigger Jenkins Build [ Build-Portal ]
on:
  push:
    branches: [ develop ]
    paths: 
       - 'frontend/**'
       - 'backend/**'
    types: [closed]
jobs:
  build:
    name: Triggering Jenkins Build [ Build-Portal ]
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
      - uses: dorny/paths-filter@v2
        id: changes
        with:
           filters: |
              backend:
                - 'backend/**'
              frontend:
                - 'frontend/**'
    - name: Trigger Build-Portal FRONTEND
      # run only if some file in 'frontend' folder was changed
      if: steps.changes.outputs.frontend == 'true'
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "UI":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...
     - name: Trigger Build-Portal BACKEND
      # run only if some file not 'backend' folder was changed
      if: steps.changes.outputs.backend == 'true'
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "API":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...
于 2021-06-11T17:21:36.897 回答