触发标签和手动作业的跨项目管道

时间:2020-07-07 17:04:48

标签: gitlab microservices gitlab-ci gitlab-api

Gitlab的跨项目管道允许我specify a branch运行管道。我没有找到类似的选项来对标签执行相同操作?

由于我的跨项目管道也有意运行,是否还可以在下游管道中运行所有手动作业?

1 个答案:

答案 0 :(得分:0)

Triggering pipelines through the API应该可以实现。

您只需要在CI脚本中添加以下内容:

- curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://gitlab.example.com/api/v4/projects/<project-id>/trigger/pipeline

并将ref更新为您所需的标签,并使用您要触发的项目更新<project-id>


对于跨项目管道的故意运行以及触发时要运行的手动作业,您可能需要重新编写下游CI文件以允许这样做,例如:

上游CI文件:

build:
  stage: build
  script:
    - echo "Do some building..."
    # Trigger downstream project (tag v1.0.0), with a random variable
    - curl --request POST --form "token=$CI_JOB_TOKEN" \
        --form "variables[RANDOM_VARIABLE]=FOO" \
        --form ref=v1.0.0 https://gitlab.com/api/v4/projects/<project_id>/trigger/pipeline

下游CI文件:

.test:template:
  stage: test
  script:
    - echo "Running some test"

test:manual:
  extends:
    - .test:template
  when: manual
  except:
    - triggers

test:triggered:
  extends:
    - .test:template
  only:
    - triggers

因此,当运行触发的作业时,test:triggered应该是您在管道中看到的唯一的test作业。

有关更多信息,请参见only/except文档。