Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 908
The Ref Avatar asked Aug 21 '20 15:08

The Ref


People also ask

What is used to restrict when a job is executed on your pipeline?

Run jobs for scheduled pipelines To configure a job to be executed only when the pipeline has been scheduled, use the rules keyword.

How do you increase the timeout of a job in GitLab?

You can set a global timeout in "Project settings -> CI/CD Pipelines -> Timeout" or "Project settings -> Builds -> Timeout" in older versions. The job-level timeout can exceed the project-level timeout but can't exceed the Runner-specific timeout.


1 Answers

This is similar to a 4 years old feature request gitlab-org/gitlab-foss issue 19813

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.

I don't want this to happen, I want it to run only if the src folder changes.
Is this possible?

The recent (July 2020) conclusion is to use only:changes/except:changes

Using the changes keyword with only or except makes it possible to define if a job should be created based on files modified by a Git push event.

Example:

I wanted this feature especially for package.json and package-lock.json because I can run npm install only if there is changes.

  only:
    changes:
      - package.json
      - package-lock.json

Warning, as noted by Matthijs Bierman in the comments, and as documented here:

Note that only: changes does not work with when: scheduled

like image 156
VonC Avatar answered Oct 09 '22 21:10

VonC