我有带有ci文件的gitlab项目:
stages:
- build
- run
build:
stage: build
script:
- (some stuff)
tags:
- my_runner_tag
except:
- triggers
when: manual
run:
stage: run
script:
- (some stuff)
tags:
- my_runner_tag
except:
- triggers
when: manual
作业在每次源代码更改时都会创建,并且只能使用gitlab界面手动运行。
现在,我希望可以使用Gitlab API触发阶段run
。尝试:
curl -X POST \
> -F token=xxxxxxxxxxxxxxx \
> -F ref=master \
> https://gitlab.xxxxx.com/api/v4/projects/5/trigger/pipeline
返回:
{"message":{"base":["No stages / jobs for this pipeline."]}}
似乎我必须定义要触发的阶段,但是我找不到通过api调用传递阶段的方法。
答案 0 :(得分:1)
您使用了错误的端点,要执行此操作,您需要遵循以下路径
列出您所有的管道并获取最新的
GET /projects/:id/pipelines
列出此管道中的作业
GET /projects/:id/pipelines/:pipeline_id/jobs
之后,您可以触发工作
POST /projects/:id/jobs/:job_id/play
答案 1 :(得分:1)
您正在告诉您的版本在除外期间一直在运行(被触发(api调用也被视为触发器))。
将工作定义更改为以下内容:
run:
stage: run
script:
- (some stuff)
tags:
- my_runner_tag
when: manual