首页 > 解决方案 > How to trigger a downstream pipeline on a specific runner with Gitlab API?

问题描述

I am trying to trigger another downstream pipeline within my pipeline using the Gitlab API because the projects are private.

I am able to trigger it initially but I keep running into issues when the downstream pipeline starts because it seems that it keeps running on some other random runner.

I've tried the following methods:

run_downstream_pipeline:
    stage: trigger_project_b_pipeline
    script:
         - 'curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=staging \
    --form "variables[CI_RUNNER_TAGS]=my_runner_tag" \
    "https://gitlab.example.com/api/v4/projects/9/trigger/pipeline"'

...or adding it as a -tag:

run_downstream_pipeline:
    stage: trigger_project_b_pipeline
    tags:
       - my_runner_tag
    script:
         - 'curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=staging \
    "https://gitlab.example.com/api/v4/projects/9/trigger/pipeline"'

...or putting it in as a ref within the url:

run_downstream_pipeline:
    stage: trigger_project_b_pipeline
    script:
         - 'curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=staging \
    "https://gitlab.example.com/api/v4/projects/9/ref/my_runner_tag/trigger/pipeline"'

The first and third methods successfully start the downstream pipeline on the wrong runner, but the second method doesn't seem to work at all.

Would appreciate any advice. Thanks!

标签: gitlabgitlab-cigitlab-api

解决方案


推荐阅读