简体   繁体   English

Gitlab CI 脚本:排除分支

[英]Gitlab CI script: exclude branches

I'm trying to improve the project building script, described in YML-file, the improvement itself seems quite trivial, but the idea of accidentally ruining the auto-builds scares me a bit.我正在尝试改进 YML 文件中描述的项目构建脚本,改进本身似乎微不足道,但是意外破坏自动构建的想法让我有点害怕。

Right now there are several branches, version tags and other stuff in the project.现在项目中有几个分支、版本标签和其他东西。

A development branch, not built by the runners would be of use, because copying a huge project somehow between virtual machines to test the build on different platforms is not convenient at all.一个不是由运行者构建的开发分支会很有用,因为在虚拟机之间以某种方式复制一个巨大的项目来测试不同平台上的构建根本不方便。 So, I want to exclude from builds some "prj-dev" branch.所以,我想从构建一些“prj-dev”分支中排除。

And there we have:我们有:

stages:
 - build
 - linuxbuild
job:
 tags:
 - win2008build
 stage: build
 script:
  # something complex

job1:
 tags:
 - linux
 stage: linuxbuild
 script:
  # something else complex

I googled and found a solution like:我用谷歌搜索并找到了一个解决方案,如:

stages:
 - build
 - linuxbuild
job:
 tags:
 - win2008build 
 branches:
  except:
    - *dev-only

But it seems that our pipelines are quite different, the tags are not git tags, they are pipeline tags.但是似乎我们的管道有很大的不同,标签不是 git 标签,它们是管道标签。 So, I'm considering rather to use a config like:所以,我正在考虑使用如下配置:

stages:
 - build
 - linuxbuild
job:
 tags:
 - win2008build 
 except:
   branches:
    - *dev-only

...which would mean "build as usual, but not my branch". ...这意味着“照常构建,但不是我的分支”。 There are complications in trying it both ways, I'm pretty sure someone should know the recipe for sure.两种方式都尝试很复杂,我很确定有人应该知道食谱。

So, if you please, -- how do I exclude my dev branch without changing the pipelines, config only?所以,如果您愿意, - 如何在不更改管道的情况下排除我的 dev 分支,仅配置? Is it possible at all?有可能吗?

All you need to do is use except in the gitlab-ci.yml file and add your branches directly below like this:您需要做的就是使用gitlab-ci.yml文件except ,并直接在下面添加您的分支,如下所示:

mybuild:
    stage: test
    image: somedockerimage
    script:
        - some script running
    except:
        - branch-name

This is working on my project without problems.这在我的项目上没有问题。

@blurryroots Kind of... In the case of commercial deployment, what you tend to do is branch off for specific features and merge back into master. @blurryroots 有点……在商业部署的情况下,您倾向于做的是针对特定功能进行分支并合并回 master。 The branch created from master can be called anything eg "Dev1-Metrics-Feature-Logger", this in turn means if you were to use "Only" tag to have the pipeline run only on the development branches you would need to change the script everytime a new branch is created, thus "except" would work better > Run testing on everything "EXCEPT" master, and then when you merge into master the other jobs designed for master will kick in.从 master 创建的分支可以称为任何东西,例如“Dev1-Metrics-Feature-Logger”,这反过来意味着如果您要使用“Only”标签让管道仅在开发分支上运行,您将需要更改脚本每次创建新分支时,“except” 会更好地工作 > 对所有“EXCEPT” master 进行测试,然后当您合并到 master 时,为 master 设计的其他作业将启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM