如何在 gitlab 中触发特定作业 [英] How to trigger a specific job in gitlab

查看:13
本文介绍了如何在 gitlab 中触发特定作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在管道中运行一个特定的作业,我认为为该作业分配一个标签,然后在 post 方法中再次指定这个标签将满足我的需求.问题是当我使用 api(post) 触发时,管道中的所有作业都是触发事件,尽管只有其中一个标记为 .

I want to run a specific job in a pipeline , I thought assigning a tag for the job and then specifying this tag again in the post method will fulfill my needs .The problem is when I trigger using the api(post) , all the jobs in the pipeline are triggered event though only one of this tagged .

gitlab-ci.yml:

gitlab-ci.yml :

工作1:脚本:- 回声你好世界!"标签:[myTag]

job1: script: - echo "helloworld!" tags : [myTag]

工作2:脚本:- 回声你好 gitlab!"

job2: script: - echo "hello gitlab!"

API 调用:curl -X POST -F token="xxx" -F ref="myTag" https://gitlab.com/api/v4/projects/12345678/trigger/pipeline

the api call : curl -X POST -F token="xxx" -F ref="myTag" https://gitlab.com/api/v4/projects/12345678/trigger/pipeline

推荐答案

向您的触发器 api 调用添加一个变量,如下所示:

add a variable to your trigger api call as shown here:

https://docs.gitlab.com/ee/ci/triggers/#making-use-of-trigger-variables

然后使用 only 属性在您的 gitlab.yml 文件中如图所示:

then use the only prperty inside your gitlab.yml file as shown here :

https://docs.gitlab.com/ee/ci/variables/#environment-variables-expressions

那么只有当变量存在时才会执行作业

例如

job1:
  script: echo "HELLO"
  only:
    variables:
      - $variables[API_CALL]=true

这篇关于如何在 gitlab 中触发特定作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆