This page will show you how to setup scheduled jobs/builds for your GitLab repository using GitLab CI/CD.
If you have not setup runners for your GitLab repository, please refer to this page.
Scheduled Builds
It is possible to make scheduled jobs that run every hour, daily, etc controlled by cron syntax. Rather than build on every merge request or on every push, you can instead make daily builds and tests.
Clicking the green "New Schedule" should bring you to the following page where you can make settings like the timing/branch of the builds.
In the above picture, I have created a scheduled job that runs on the "version10.0beta" branch everyday at 12am.
If you set a scheduled build to run on a branch, it will simply trigger the .yml script as normal. You may have other jobs that you want to run on pushes/merge requests but NOT on schedules. To resolve this issue, we can make use of the keyword schedules' in the "only" and "except" portion of the yml.
only: - schedules
except: - schedules
Below is a sample job, that when a schedule is setup for a branch, runs 2 jobs. One that builds and uploads builds to MyConfigura, and one that just runs tests.
variables:
CUSTOM_REPO: "myBrand"
BASE_VERSION: "version10.0"
.SetupBuildEnv:
before_script:
# Base has to be cloned outside the repo, because of default git clean options
- cd ..
- if not exist base (git clone https://gitlab-ci-token:%CI_JOB_TOKEN%@git.configura.com/cet/external/base.git) # Set CM environment variables + add custom to cm class_path args
- powershell.exe -file "base/bin/createsetenv.ps1"
- call setenv.cmd # Setup base branch
- cd base
- git checkout %BASE_VERSION%
- git reset --hard
- git clean -fd
- git pull # Make symlink in extensions/custom/myBrand to to match folder structure we usually get.
# (extensions/custom/xxx)
# We need this until they fix -https://gitlab.com/gitlab-org/gitlab-runner/issues/4167
- cd ..
- if exist "extensions" rmdir /s /q "extensions"
- mkdir "extensions/custom"
- mklink /D "extensions/custom/%CUSTOM_REPO%" "%CI_PROJECT_DIR%" # Clean write folder + BuildOutput
- if exist write rd /s /q write
- if exist BuildOutput rd /s /q BuildOutput # Always runs even script/build fails.
after_script:
# We have to move BuildLogs within the original repo if we want to upload it
# (Artifacts limitation that isn't clearly documented by Gitlab :D )
- cd %CI_PROJECT_DIR%/..
- move BuildLogs %CI_PROJECT_DIR%
BuildAndUpload:
tags:
- build
variables:
GIT_STRATEGY: Fetch
GIT_DEPTH: 1000
extends: .SetupBuildEnv
script:
# Make operator/cop recognise the workspace
- cd %CI_PROJECT_DIR%/..
- powershell.exe -file "base/cm/core/test/runner/cop/Workspace/createcopcmws.ps1" # Build/Upload - Set uploadname as "runner-<branch>-<job_id>"
- cop clean
- cop repair
- cop build [myBrand] -minggwformat
- cop upload [myBrand] /uploadname="runner-%CI_COMMIT_REF_NAME%-%CI_JOB_ID%"
# Upload build logs even on job failure so we know what went wrong
artifacts:
when: always
paths:
- BuildLogs/* # Only on scheduled jobs.
only:
- schedules
Test:
tags:
- build
variables:
GIT_STRATEGY: Fetch
GIT_DEPTH: 1000
extends: .SetupBuildEnv
script:
# Make operator/cop recognise the workspace
- cd %CI_PROJECT_DIR%/..
- powershell.exe -file "base/cm/core/test/runner/cop/Workspace/createcopcmws.ps1" # Just test
- cop clean
- cop repair
- cop build [myBrand TestGroup] -minggwformat
# Upload build logs even on job failure so we know what went wrong
artifacts:
when: always
paths:
- BuildLogs/* # Only on scheduled jobs.
only:
- schedules
The yml is similar to the one found on this page, but we have removed the "simulated merge" since we are building on the target branch itself, and we have set the jobs to trigger on only schedules and removed the conditions for triggering on merger requests.
Comments
0 comments
Please sign in to leave a comment.