当一定的条件满足后, Gitlab会触发项目中的 .gitlab-ci.yml 中定义的pipeline, 典型的场景有


1、当仓库中某个分支有代码push的时候


2、定期触发:例如某个分支每个月22号触发, 或者每天触发 (使用cron语法,用 Fugit解析)


3、使用API来外部系统触发


根据触发条件,我们可以把gitlab pipeline分为以下几种:


触发方式pipeline分类所带的refspec(决定了runner拉取哪些代码)
pushPipeline for Branches

+<sha>:refs/pipelines/<id> 

+refs/heads/<name>:refs/remotes/origin/<name>

pushpipeline for Tags

+<sha>:refs/pipelines/<id> 

+refs/tags/<name>:refs/tags/<name>

pushPipeline for Merge Requests+<sha>:refs/pipelines/<id>
定时

人工

API


每次push触发的pipeline

push后, push的每一个branch,本次push在一个branch的最后一个提交触发一个pipeline

push中如果有tag,触发tag pipeline

push在一个merge request的source分支,则有可能会触发一个 merge reqest pipeline, 

在界面上规划一个Pipeline: 

1、触发者有目标分支的merge权限

2、.gitlab-ci.yml有效,不能有语法错误

 规划的Pipeline有一个owner,执行此pipeline是使用owner的密码执行。



具体的触发方式可以参考 rule 的if语句:https://docs.gitlab.com/ee/ci/jobs/job_control.html#common-if-clauses-for-rules


ValueDescription
apiFor pipelines triggered by the pipelines API.
chatFor pipelines created by using a GitLab ChatOps command.
externalWhen you use CI services other than GitLab.
external_pull_request_eventWhen an external pull request on GitHub is created or updated. See Pipelines for external pull requests.
merge_request_eventFor pipelines created when a merge request is created or updated. Required to enable merge request pipelines, merged results pipelines, and merge trains.
parent_pipelineFor pipelines triggered by a parent/child pipeline with rules. Use this pipeline source in the child pipeline configuration so that it can be triggered by the parent pipeline.
pipelineFor multi-project pipelines created by using the API with CI_JOB_TOKEN, or the trigger keyword.
pushFor pipelines triggered by a git push event, including for branches and tags.
scheduleFor scheduled pipelines.
triggerFor pipelines created by using a trigger token.
webFor pipelines created by using Run pipeline button in the GitLab UI, from the project’s CI/CD > Pipelines section.
webideFor pipelines created by using the WebIDE.