<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Pipelines for Merge Requests > 原文:[https://docs.gitlab.com/ee/ci/merge_request_pipelines/](https://docs.gitlab.com/ee/ci/merge_request_pipelines/) * [Prerequisites](#prerequisites) * [Configuring pipelines for merge requests](#configuring-pipelines-for-merge-requests) * [Use `rules` to run pipelines for merge requests](#use-rules-to-run-pipelines-for-merge-requests) * [Use `only` or `except` to run pipelines for merge requests](#use-only-or-except-to-run-pipelines-for-merge-requests) * [Excluding certain jobs](#excluding-certain-jobs) * [Excluding certain branches](#excluding-certain-branches) * [Pipelines for Merged Results](#pipelines-for-merged-results-premium) * [Merge Trains](#merge-trains-premium) * [Important notes about merge requests from forked projects](#important-notes-about-merge-requests-from-forked-projects) * [Additional predefined variables](#additional-predefined-variables) * [Troubleshooting](#troubleshooting) * [Two pipelines created when pushing to a merge request](#two-pipelines-created-when-pushing-to-a-merge-request) * [Two pipelines created when pushing an invalid CI configuration file](#two-pipelines-created-when-pushing-an-invalid-ci-configuration-file) # Pipelines for Merge Requests[](#pipelines-for-merge-requests "Permalink") 在 GitLab 11.6 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/15310) . 在[基本配置中](../pipelines/pipeline_architectures.html#basic-pipelines) ,每次更改被推送到分支時,GitLab 都會運行管道. 如果希望管道**僅**在創建或更新合并請求時運行作業,則可以將*管道用于合并請求* . 在用戶界面中,這些管道被標記為`detached` . 否則,這些管道看起來與其他管道相同. 具有開發者[權限的](../../user/permissions.html)任何用戶都可以為合并請求運行管道. [![Merge request page](https://img.kancloud.cn/47/f9/47f9325a9bb9a995c2b6e4f32d394f4b_971x87.png)](img/merge_request.png) **Note:** If you use this feature with [merge when pipeline succeeds](../../user/project/merge_requests/merge_when_pipeline_succeeds.html), pipelines for merge requests take precedence over the other regular pipelines. ## Prerequisites[](#prerequisites "Permalink") 要為合并請求啟用管道: * 您的存儲庫必須是 GitLab 存儲庫,而不是[外部存儲庫](../ci_cd_for_external_repos/index.html) . * [在 GitLab 11.10 和更高版本中](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/25504) ,您必須使用 GitLab Runner 11.9. ## Configuring pipelines for merge requests[](#configuring-pipelines-for-merge-requests "Permalink") 要為合并請求配置管道,您需要配置[CI / CD 配置文件](../yaml/README.html) . 有幾種不同的方法可以做到這一點: ### Use `rules` to run pipelines for merge requests[](#use-rules-to-run-pipelines-for-merge-requests "Permalink") 當使用`rules` ,這是首選方法,我們建議從[`workflow:rules`模板開始,](../yaml/README.html#workflowrules-templates)以確保基本配置正確. 該鏈接提供了有關如何執行此操作以及如何進行自定義的說明. ### Use `only` or `except` to run pipelines for merge requests[](#use-only-or-except-to-run-pipelines-for-merge-requests "Permalink") If you want to continue using `only/except`, this is possible but please review the drawbacks below. 使用此方法時,只需指定`only: - merge_requests`每個作業的`only: - merge_requests` . 在此示例中,管道包含配置為在合并請求上運行的`test`作業. `build`和`deploy`作業沒有`only: - merge_requests`參數,因此它們將不會在合并請求上運行. ``` build: stage: build script: ./build only: - master test: stage: test script: ./test only: - merge_requests deploy: stage: deploy script: ./deploy only: - master ``` #### Excluding certain jobs[](#excluding-certain-jobs "Permalink") `only: [merge_requests]`參數的行為是, *只有*具有該參數的作業*才*在合并請求的上下文中運行; 沒有其他作業將運行. 但是,您可以反轉此行為,并運行*除*一兩個*之外的*所有作業. 考慮下面的管道,作業`A` , `B`和`C` 假設您要: * 所有管道始終運行`A`和`B` * `C`僅針對合并請求運行. 為此,可以如下配置`.gitlab-ci.yml`文件: ``` .only-default: &only-default only: - master - merge_requests - tags A: <<: *only-default script: - ... B: <<: *only-default script: - ... C: script: - ... only: - merge_requests ``` Therefore: * 由于`A`和`B`在所有情況下都具有`only:`執行規則,因此它們將始終運行. * 由于`C`指定僅針對合并請求運行,因此它將不會針對除合并請求管道之外的任何管道運行. 這可以幫助您避免為所有作業添加`only:`規則,以使其始終運行. 您可以使用這種格式來設置評論應用,以幫助節省資源. #### Excluding certain branches[](#excluding-certain-branches "Permalink") [`only`](../yaml/README.html#onlyexcept-basic)使用[/ `except`](../yaml/README.html#onlyexcept-basic)時,合并請求的管道需要特殊處理. 與普通的分支引用(例如`refs/heads/my-feature-branch` )不同,合并請求引用使用特殊的 Git 引用,看起來像`refs/merge-requests/:iid/head` . 因此,以下配置將**無法**正常工作: ``` # Does not exclude a branch named "docs-my-fix"! test: only: [merge_requests] except: [/^docs-/] ``` 相反,可以將[`$CI_COMMIT_REF_NAME`預定義環境變量](../variables/predefined_variables.html)與[`only:variables`](../yaml/README.html#onlyvariablesexceptvariables)結合使用以完成此行為: ``` test: only: [merge_requests] except: variables: - $CI_COMMIT_REF_NAME =~ /^docs-/ ``` ## Pipelines for Merged Results[](#pipelines-for-merged-results-premium "Permalink") 閱讀[有關合并結果的管道](pipelines_for_merged_results/index.html)的[文檔](pipelines_for_merged_results/index.html) . ### Merge Trains[](#merge-trains-premium "Permalink") 閱讀[有關合并火車](pipelines_for_merged_results/merge_trains/index.html)的[文檔](pipelines_for_merged_results/merge_trains/index.html) . ## Important notes about merge requests from forked projects[](#important-notes-about-merge-requests-from-forked-projects "Permalink") 請注意,當前行為可能會更改. 在通常的貢獻流程中,外部貢獻者遵循以下步驟: 1. 分叉一個父項目. 2. 從分支項目中創建一個以父項目中的`master`分支為目標的合并請求. 3. 管道在合并請求上運行. 4. 父項目的維護者檢查管道結果,如果最新的管道通過,則合并到目標分支. 當前,這些管道是在**派生**項目中創建的,而不是在父項目中創建的. 這意味著您不能完全信任管道結果,因為從技術上講,外部貢獻者可以通過在派生項目中調整其 GitLab Runner 來掩蓋其管道結果. GitLab 不允許在父項目中創建這些管道有多種原因,但是最大的原因之一是安全性問題. 外部用戶可以通過修改`.gitlab-ci.yml` (可能是某種憑據)從父項目中竊取秘密變量. 這不應該發生. 我們正在討論一種安全的解決方案,該解決方案針對從分支項目提交的合并請求運行管道,請參閱[有關權限擴展的問題](https://gitlab.com/gitlab-org/gitlab/-/issues/11934) . ## Additional predefined variables[](#additional-predefined-variables "Permalink") 通過將管道用于合并請求,GitLab 將其他預定義變量公開給管道作業. 這些變量包含關聯的合并請求的信息,因此將您的作業與[GitLab 合并請求 API](../../api/merge_requests.html)集成非常有用. 您可以在[參考表中](../variables/predefined_variables.html)找到可用變量的列表. 變量名稱以`CI_MERGE_REQUEST_`前綴開頭. ## Troubleshooting[](#troubleshooting "Permalink") ### Two pipelines created when pushing to a merge request[](#two-pipelines-created-when-pushing-to-a-merge-request "Permalink") 如果使用`rules`時遇到重復的管道,請查看[`rules`和`only` / `except`之間](../yaml/README.html#differences-between-rules-and-onlyexcept)的[重要區別](../yaml/README.html#differences-between-rules-and-onlyexcept) ,這將幫助您正確設置起始配置. 如果您在使用`only/except`時看到兩個管道,請參見上述與`only/except`一起使用的注意事項(或者,考慮使用`rules` ). ### Two pipelines created when pushing an invalid CI configuration file[](#two-pipelines-created-when-pushing-an-invalid-ci-configuration-file "Permalink") 推送到具有無效 CI 配置文件的分支會觸發兩種類型的失敗管道的創建. 一個管道是失敗的合并請求管道,另一個管道是失敗的分支管道,但兩者都是由相同的無效配置引起的. 在極少數情況下,會創建重復的管道. 有關詳細信息,請參[見此問題](https://gitlab.com/gitlab-org/gitlab/-/issues/201845) .
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看