Gitlab-CI, run on schedule but only if there are changes

Viewed 3208

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?

2 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

You need to create separate Branch dev on Git where you store your an hourly changes of code and at the end of the day You can merge it with Master branch which trigger build on Git CI.

Generally Master is default branch for deployment of Git CI. you can change it to different branch as well.

Related