Gitlab CI:从单个提交创建多个构建

时间:2019-05-07 17:55:11

标签: gitlab gitlab-ci gitlab-ci-runner

我当前的gitlab配置非常简单,如下所示

stages:
 - build

before_script:
  - some commands here

build-after-commit:
 stage: build
 script:
  - some command here
 artifacts:
  expire_in: 1 day
  when: on_success
  name: name here
  paths:
    - build/*.zip

我要使用不同的设置两次运行提交后构建的部件。我期待这样的事情

stages:
 - build

before_script:
  - some commands here

build-after-commit:
 stage: build
 script:
  - some command here
 artifacts:
  expire_in: 1 day
  when: on_success
  name: name1 here
  paths:
    - build/*.zip

 # run it again with different settings
 stage: build
 script:
  - Different script here
 artifacts:
  expire_in: 1 day
  when: on_success
  name: name2 here
  paths:
    - build/*.zip 

因此,基本上,在第二次运行中,脚本将有所不同,并且输出文件的名称将有所不同。我该怎么办?

1 个答案:

答案 0 :(得分:1)

直接的方法是在构建阶段进行另一项工作。

例如

stages:
 - build

before_script:
  - some commands here


build-after-commit:
    stage: build
    script:
    - some command here
    artifacts:
    expire_in: 1 day
    when: on_success
    name: name1 here
    paths:
    - build/*.zip

build-after-commit2:
    stage: build
    script:
    - Different script here
    artifacts:
    expire_in: 1 day
    when: on_success
    name: name2 here
    paths:
        - build/*.zip

如果您在同一阶段(build-after-commit2中定义build,它甚至会与build-after-commit并行运行。 在这种情况下,我不认为有两个工作是不好的设计,因为它们实际上彼此之间有很大不同,即不同的脚本和不同的工件名称。