“.gitlab-ci.yml” pipeline returns 错误“找不到下游项目”
".gitlab-ci.yml" pipeline returns an error `downstream project could not be found`
所有项目的路径均有效。我可以确认这一点,因为下面的代码可以运行并运行一个子管道:
stage: multi_project_test
trigger:
project: "my_organization/my_group/project_1"
strategy: depend
但是下面的代码导致 downstream project could not be found
:
stages:
- test
- multi_project_test
- deploy
include:
- local: ".gitlab-ci-common.yml"
test:
extends: .test_stage_common
script:
- poetry install -vv
- !reference [.test_stage_common, script]
downstream_pipelines:
stage: multi_project_test
parallel:
matrix:
- DOWNSTREAM_PROJECT:
[
my_organization/my_group/project_1,
my_organization/my_group/project_2,
my_organization/my_group/project_3,
my_organization/my_group/project_4,
]
trigger:
project: $DOWNSTREAM_PROJECT
strategy: depend
variables:
PIPELINE_TYPE: "multi-project-pipeline"
为什么会出现错误?
很多地方允许使用变量,但是trigger:project
不支持使用变量。有一个 open issue 跟踪使此功能适用于 trigger:project
。
从 GitLab 15.0 开始,可以在 .gitlab-ci.yml
中的以下位置使用变量:
Definition
Can be expanded?
Expansion place
after_script
yes
Script execution shell
artifacts:name
yes
Runner
before_script
yes
Script execution shell
cache:key
yes
Runner
environment:name
yes
GitLab
environment:url
yes
GitLab
except:variables:[]
no
n/a
image
yes
Runner
include
yes
GitLab
only:variables:[]
no
n/a
resource_group
yes
GitLab
rules:if
no
n/a
script
yes
Script execution shell
services:[]:name
yes
Runner
services:[]
yes
Runner
tags
yes
GitLab
variables
yes
GitLab/Runner
有关完整参考,包括可以使用的其他 files/places 变量,请参阅文档:where variables can be used。
作为解决方法,您可以改为在 script:
中触发项目,should provide the same effect.
trigger:
image: alpine
parallel:
matrix:
- DOWNSTREAM_PROJECT_ID: ["1234", "5678"]
script:
- apk add --no-cache curl
- curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=main "https://${CI_SERVER_HOST}/api/v4/projects/${DOWNSTREAM_PROJECT_ID}/trigger/pipeline"
所有项目的路径均有效。我可以确认这一点,因为下面的代码可以运行并运行一个子管道:
stage: multi_project_test
trigger:
project: "my_organization/my_group/project_1"
strategy: depend
但是下面的代码导致 downstream project could not be found
:
stages:
- test
- multi_project_test
- deploy
include:
- local: ".gitlab-ci-common.yml"
test:
extends: .test_stage_common
script:
- poetry install -vv
- !reference [.test_stage_common, script]
downstream_pipelines:
stage: multi_project_test
parallel:
matrix:
- DOWNSTREAM_PROJECT:
[
my_organization/my_group/project_1,
my_organization/my_group/project_2,
my_organization/my_group/project_3,
my_organization/my_group/project_4,
]
trigger:
project: $DOWNSTREAM_PROJECT
strategy: depend
variables:
PIPELINE_TYPE: "multi-project-pipeline"
为什么会出现错误?
很多地方允许使用变量,但是trigger:project
不支持使用变量。有一个 open issue 跟踪使此功能适用于 trigger:project
。
从 GitLab 15.0 开始,可以在 .gitlab-ci.yml
中的以下位置使用变量:
Definition | Can be expanded? | Expansion place |
---|---|---|
after_script |
yes | Script execution shell |
artifacts:name |
yes | Runner |
before_script |
yes | Script execution shell |
cache:key |
yes | Runner |
environment:name |
yes | GitLab |
environment:url |
yes | GitLab |
except:variables:[] |
no | n/a |
image |
yes | Runner |
include |
yes | GitLab |
only:variables:[] |
no | n/a |
resource_group |
yes | GitLab |
rules:if |
no | n/a |
script |
yes | Script execution shell |
services:[]:name |
yes | Runner |
services:[] |
yes | Runner |
tags |
yes | GitLab |
variables |
yes | GitLab/Runner |
有关完整参考,包括可以使用的其他 files/places 变量,请参阅文档:where variables can be used。
作为解决方法,您可以改为在 script:
中触发项目,should provide the same effect.
trigger:
image: alpine
parallel:
matrix:
- DOWNSTREAM_PROJECT_ID: ["1234", "5678"]
script:
- apk add --no-cache curl
- curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=main "https://${CI_SERVER_HOST}/api/v4/projects/${DOWNSTREAM_PROJECT_ID}/trigger/pipeline"