【问题标题】:Pushing to "qa" branch did not trigger "qa" build, instead it triggers "dev" build推送到“qa”分支不会触发“qa”构建,而是触发“dev”构建
【发布时间】:2021-11-21 01:33:45
【问题描述】:

我有这个 ci.yml 工作流程。

jobs:
  dev_build:
    if: ${{ !(contains(github.base_ref, 'master') || contains(github.base_ref, 'main') || contains(github.head_ref, 'master') || contains(github.head_ref, 'main') || contains(github.base_ref, 'qa') || contains(github.head_ref, 'qa')) }}

       .
       .
       .

   qa_build:
    if: ${{ contains(github.base_ref, 'qa') || contains(github.head_ref, 'qa') }}
       .
       .
       .

但是每次我推送到“qa”分支时,它都会触发“dev_build”而不是“qa_build”。我的情况有问题吗?

谢谢!

【问题讨论】:

    标签: github continuous-integration github-actions


    【解决方案1】:

    根据documentation

    工作流运行中拉取请求的 base_ref 或目标分支。仅当触发工作流运行的事件为 pull_request 或 pull_request_target 时,此属性才可用。

    工作流运行中拉取请求的 head_ref 或源分支。仅当触发工作流运行的事件为 pull_request 或 pull_request_target 时,此属性才可用。

    如此简单的推送到 qa 分支在这里不起作用,因为这些值是在 pull_request 和 pull_request_target 事件中填充的。

    第一个工作被触发是因为这部分!(contains(github.base_ref, 'master')

    您还有 onlu CI 触发器,而不是 PR 触发器。看看这个区别:

    Ci 触发器:

    使用 PR 触发器:

    我对此进行了以下测试:

    name: so-034-conditions
    
    on:
      push:
        branches: [ master, main, qa ]
      pull_request:
        branches:
          - main
      workflow_dispatch:
    
    jobs:
      dev_build:
        runs-on: ubuntu-latest
        if: ${{ !(contains(github.base_ref, 'master') || contains(github.base_ref, 'main') || contains(github.head_ref, 'master') || contains(github.head_ref, 'main') || contains(github.base_ref, 'qa') || contains(github.head_ref, 'qa')) }}
        steps:
          - name: Checkout this repo
            uses: actions/checkout@v2
            with:
              fetch-depth: 2
          - name: Dump GitHub context
            env:
              GITHUB_CONTEXT: ${{ toJSON(github) }}
            run: echo "$GITHUB_CONTEXT"
          - name: Test1
            id: test1
            run: |
              
              echo "Deploying $GITHUB_REF"
              echo "Deploying ${{ github.event_name }}"
      qa_build:
        runs-on: ubuntu-latest
        if: ${{ contains(github.base_ref, 'qa') || contains(github.head_ref, 'qa') }}
        steps:
          - name: Checkout this repo
            uses: actions/checkout@v2
            with:
              fetch-depth: 2
          - name: Dump GitHub context
            env:
              GITHUB_CONTEXT: ${{ toJSON(github) }}
            run: echo "$GITHUB_CONTEXT"
          - name: Test1
            id: test1
            run: |
              echo "${{ github.base_ref }}"
              echo "Deploying ${{ github.event_name }}"
    

    【讨论】:

    • 嗨,我的 ci.yml 文件中有这个。似乎我也有 PR 触发器:push:branches:[master,develop,qa] pull_request:branches:[master,develop,qa]
    • 你有公关吗?如果没有,您将不会收到 pull_request 事件。只有这样,您的管道才能按预期工作。您需要打开 PR,然后推送到分支。请检查这个。
    猜你喜欢
    • 2012-08-30
    • 2016-12-09
    • 2021-01-13
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 2011-02-08
    相关资源
    最近更新 更多