Gitlab-CI,按计划运行,但前提是有变化 [英] Gitlab-CI, run on schedule but only if there are changes
问题描述
我想每天部署一次我的项目,但前提是有更改.我可以在每个特定小时内进行部署,并且我很乐意使用预定的管道来触发和部署.
I'd like to deploy my project once per day, but only if there have been changes. There is a specific hour each that I am able to deploy during and I am comfortable with using a scheduled pipeline to trigger and deploy.
但是,并非总是有需要部署的更改.理想情况下,如果自上次部署以来对代码库没有任何更改,则管道当天不会运行.
However, there aren't always changes that require deployment. Ideally, if there have been no changes to the code base since the last deployment, the pipeline wouldn't run that day.
有没有办法实现这种行为?
Is there any way to achieve this behaviour?
推荐答案
这类似于一个 4 年前的功能请求 gitlab-org/gitlab-foss
问题 19813
This is similar to a 4 years old feature request gitlab-org/gitlab-foss
issue 19813
我有一个相当大的项目,我正在使用带有 Pages 的 GitLab CI 来部署它,但是,当我在 repo 中更改任何内容时,它会运行 CI.
GitLab CI only execute when a certain folder has changed
I have quite a large project, and I'm using GitLab CI with Pages to deploy it, however, when I change anything in the repo, it runs CI.
我不希望这种情况发生,我希望它仅在 src
文件夹更改时运行.
这可能吗?
I don't want this to happen, I want it to run only if the src
folder changes.
Is this possible?
最近(2020 年 7 月)的结论是使用 only:changes
/except:changes
The recent (July 2020) conclusion is to use only:changes
/except:changes
将 changes
关键字与 only
或 except
一起使用可以定义是否应根据 Git 修改的文件创建作业推送事件.
Using the
changes
keyword withonly
orexcept
makes it possible to define if a job should be created based on files modified by a Git push event.
例子:
我特别想为 package.json
和 package-lock.json
提供此功能,因为只有在发生更改时我才能运行 npm install
.
I wanted this feature especially for
package.json
andpackage-lock.json
because I can runnpm install
only if there is changes.
仅限
only:
changes:
- package.json
- package-lock.json
警告,如 Matthijs Bierman 在 评论,以及 记录在这里:
Warning, as noted by Matthijs Bierman in the comments, and as documented here:
请注意,only: changes
not 与 when:scheduled
这篇关于Gitlab-CI,按计划运行,但前提是有变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!