如何在GitLab Runner中使用外部存储库?

时间:2019-12-26 09:41:59

标签: gitlab

我的GitLab中有两个项目。 因为一个是后端(Golang) 另一个是Frontend(Vue.js)

我想在更新bakend代码时使用后端和前端触发CI。 所以我在这样的后端项目中有一个.gitlab-ci.yml

stages:
  - backendCI
  - frontendCI

backendCI:
  image: golang:latest
  stage: backendCI
  script:
    - make all

frontendCI:
  image: node:latest
  stage: frontendCI
  script:
    - npm install
    - npm run build 

  dependencies:
    - repository: sw/frontend
      on: develop

但是有一个错误:错误:Jobs:frontend依赖项应该是一个字符串数组 我不知道如何在后端运行程序中使用前端存储库。

1 个答案:

答案 0 :(得分:0)

该错误表示yaml文件无效。您误解了dependencies的用法,该用法仅引用先前的作业以从中获取工件。

如果我很了解您的情况,则您有2个单独的存储库,因此您可以有2个单独的.gitlab-ci.yml,并且可以使用API轻松触发另一个管道:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \ 
"https://gitlab.example.com/api/v4/projects/ID/pipeline?ref=develop"

在后端.gitlab-ci.yml中进行调用,以引用前端项目(将URL中的ID替换为前端项目的ID)

如果您是Gitlab Premium(版本> = 11.8),则有一个本机syntax来触发跨项目管道。