如何在gitlab中触发特定作业 [英] How to trigger a specific job in 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 :
job1: 脚本: -回声"helloworld!" 标签:[myTag]
job1: script: - echo "helloworld!" tags : [myTag]
job2: 脚本: -回声你好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屋!