Problem to solve
This is a beginner question. I know to add a “.gitlab-ci.yml” to build the project on push. I am good with that. But, I also want to have a builder that will do a static analysis each evening at 8:00. So I want to have one run on push to build and one run on a schedule. I did see the comment on down stream pipelines but the trigger is different so I could not see that working. I suspect that this is not possible. I was able to do it with GitEa because they put the yml files in a folder instead of at the root of the project.
Versions
Please add an x whether options apply, and add the version information.
- Self-managed
-
GitLab.com SaaS
- Dedicated
Hi @jrivord,
welcome to the forum! Good news: this works in GitLab too. You still only need one .gitlab-ci.yml, and rules: decides which jobs run for a push and which run for a schedule.
-
Create the schedule. Go to Build > Pipeline schedules > New schedule, set the interval to 0 20 * * * (daily at 8 PM), and choose your timezone. Optionally, add a variable such as SCHEDULE_TYPE = static_analysis. That helps once you have more than one schedule.
-
Use rules to split the jobs:
stages:
- build
- analyze
build:
stage: build
script:
- echo "Building on push"
rules:
- if: $CI_PIPELINE_SOURCE == "push"
static-analysis:
stage: analyze
script:
- echo "Running nightly static analysis"
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "static_analysis"
Pushes run only build. The 8 PM schedule runs only static-analysis.
- Optional: keep things in separate files, like in Gitea. Move each job into its own file and include them:
include:
- local: .gitlab/ci/build.yml
- local: .gitlab/ci/static-analysis.yml
Worth knowing: if you want GitLab’s built-in scanners rather than your own tool, the SAST template can be included the same way and controlled with the same schedule rule.
Docs for further reading:
- Pipeline schedules: creating schedules and setting schedule variables
rules:: all the conditions, including $CI_PIPELINE_SOURCE values
Let us know how it goes, or share your .gitlab-ci.yml if you get stuck.