Fla*_*vio 7 pipeline gitlab gitlab-ci
我正在尝试为 GitLab 中的一个项目运行 2 个管道,但我找不到任何方法来做到这一点。
在 gitlab CI 中,您无法显式地为一个项目创建多个管道。在某些情况下,多个管道会同时运行,例如当您有仅针对合并请求运行的作业和不针对合并请求运行的其他作业时。
也就是说,有一些方法可以获得彼此独立运行多个系列作业的效果。
如果您想为同一个项目启动 2 个管道,您可以使用管道触发器。此方法仅限于 2 个管道,并且 gitlab CI 不适合以这种方式使用。通常,触发器用于启动另一个项目的管道。
一切尽在您的.gitlab-ci.yml:
stages:
- start
- build
###################################################
# First pipeline #
###################################################
start_other_pipeline:
stage: start
script:
# Trigger a pipeline for current project on current branch
- curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=$CI_COMMIT_REF_NAME $CI_API_V4_URL/projects/$CI_PROJECT_ID/trigger/pipeline
except:
- pipelines
build_first_pipeline:
stage: build
script:
- echo "Building first pipeline"
except:
- pipelines
###################################################
# Second pipeline #
###################################################
# Will run independently of the first pipeline.
build_second_pipeline:
stage: build
script:
- echo "Building second pipeline"
only:
- pipelines
Run Code Online (Sandbox Code Playgroud)
要清理 a 的混乱.gitlab-ci.yml,您可以使用include关键字:
# .gitlab-ci.yml
include:
- '/first-pipeline.yml'
- '/second-pipeline.yml'
stages:
- start
- build
# This starts the second pipeline. The first pipeline is already running.
start_other_pipeline:
stage: start
script:
# Trigger a pipeline for current project on current branch
- curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=$CI_COMMIT_REF_NAME $CI_API_V4_URL/projects/$CI_PROJECT_ID/trigger/pipeline
except:
- pipelines
Run Code Online (Sandbox Code Playgroud)
# first-pipeline.yml
build_first_pipeline:
stage: build
script:
- echo "Building first pipeline"
except:
- pipelines
Run Code Online (Sandbox Code Playgroud)
# second-pipeline.yml
build_second_pipeline:
stage: build
script:
- echo "Building second pipeline"
only:
- pipelines
Run Code Online (Sandbox Code Playgroud)
其有效的原因在于使用only和except工作中。带有标记的职位
except:
- pipelines
Run Code Online (Sandbox Code Playgroud)
由于来自另一个管道的触发器,管道启动时不会运行,因此它们不会在第二个管道中运行。另一方面,
only:
- pipelines
Run Code Online (Sandbox Code Playgroud)
其作用恰恰相反,因此这些作业仅在管道被另一个管道触发时运行,因此它们仅在第二个管道中运行。
在 gitlab CE 12.2 中,可以定义有向无环图来指定作业运行的顺序。这样,只要作业所依赖的作业(使用needs)完成,作业就可以开始。
| 归档时间: |
|
| 查看次数: |
10622 次 |
| 最近记录: |