git 仅特定分支上的 GitLab CI 管道

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46948990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:10:13  来源:igfitidea点击:

GitLab CI Pipeline on specific branch only

gitcontinuous-integrationgitlabpipelinegitlab-ci

提问by ProximaCygni

I'm trying to implement GitLab CI Pipelines to build and deploy an Angular app. In our project we have two general branches: master(for production only) and develop. For development we create feature/some-featurebranches from developbranch. When development finished, we create merge request from feature/some-featureto develop. When merge request approved and merged into developbranch I want to run a Pipeline in order to build application and deploy the build on some environment.

我正在尝试实施 GitLab CI Pipelines 来构建和部署 Angular 应用程序。在我们的项目中,我们有两个通用分支:(master仅用于生产)和develop. 对于开发,我们feature/some-featuredevelop分支创建分支。开发完成后,我们从feature/some-featureto创建合并请求develop。当合并请求被批准并合并到develop分支时,我想运行一个管道以构建应用程序并在某些环境中部署构建。

I use the following setup in .gitlab-ci.yml:

我在 .gitlab-ci.yml 中使用以下设置:

image: node:7.5-configured

stages:
    - build
    - deploy

build_job:
    stage: build
    only:
        - develop
    script:
        - /bin/bash <some script here>

...

The problem is that Pipeline executed every time I push into any feature/some-featurebranch. What's wrong with my setup? How can I force the Pipeline to be executed onlywhen push performed into developbranch directly?

问题是每次我推入任何feature/some-feature分支时都会执行流水线。我的设置有什么问题?develop直接推送到分支时,如何才能强制执行流水线?

SolutionIt was my mistake - I had two different .gitlab-ci.yml files in developbranch and feature/some-featurebranch.

解决方案这是我的错误 - 我在develop分支和feature/some-feature分支中有两个不同的 .gitlab-ci.yml 文件。

回答by ProximaCygni

It was my mistake - I had two different .gitlab-ci.yml files in developbranch and feature/some-featurebranch and that's why the Pipeline was executed for all branches.

这是我的错误 - 我在develop分支和feature/some-feature分支中有两个不同的 .gitlab-ci.yml 文件,这就是为所有分支执行管道的原因。