Schedule or trigger jobs in gitlab-ci

11.5k views Asked by At

I want to run a heavy test only once per day in Gitlab-ci. Is it possible schedule a job? Or is it possible to set it to manual and trigger it using the API?

3

There are 3 answers

0
Shengis On

It's a patch up job, but you could use triggers with a if statement :

test_app:
  stage: test
  script:
  - if [ -n "${DO_TESTS}" ]; then make test; fi

And define the variable in the cron that make the call :

curl --request POST \
  --form token=TOKEN \
  --form ref=master \
  --form "variables[DO_TESTS]=true" \
  https://gitlab.example.com/api/v3/projects/9/trigger/builds

See the doc : https://docs.gitlab.com/ce/ci/triggers/README.html

2
VonC On

This is possible, and will be improved in GitLab 11.6 (Dec. 22nd)

See gitlab-org/gitlab-ce issue 20422:

Currently all variables are shown in UI: http://docs.gitlab.com/ce/ci/triggers/README.html#pass-build-variables-to-a-trigger

This is sometimes problematic, e.g. when you pass individual secrets to the build, which could not be placed in a protected variable and should not be visible to all team members.

It can also be problematic even for some non-protected variables if they are unintentionally passed around in a screenshot/screen sharing.

Proposal

  • Variable names will still be visible by default
  • Variables values will be censored by default with asterix *******
  • Variable values are toggle-able with a button
  • The button is only available to maintainers

https://gitlab.com/gitlab-org/gitlab-ce/uploads/1dc4f635096c16322801f3deeecf09ab/image.png

2
DerMiggel On

It's possible to schedule a pipeline since GitLab 9.1, see: https://docs.gitlab.com/ce/user/project/pipelines/schedules.html

Currently (i.e. with version 9.2) it can be configured as follows:

  1. Navigate to your project's Pipelines ➔ Schedules and click the New Schedule button.
  2. Fill in the form
  3. Hit Save pipeline schedule for the changes to take effect.