Claus-Theodor Riegg
9 years
Andreas Vöst
2 years
Andreas Vöst
2 years
Moritz Kraus
2 years
Emma Heinle
3 years

GitLab scheduled pipeline: Don't notify owner

Updated . Posted . Visible to the public.

The owner of a scheduled CI/CD pipeline in GitLab will always be notified if the pipeline fails.

Follow these steps if you don't want this:

  1. Create a Project Access Token with api scope and maintainer role
  2. Create the scheduled pipeline with that token:
    curl --request POST --header "PRIVATE-TOKEN: ${TOKEN}" \
      --form description="Daily pipeline check" \
      --form ref="main" \
      --form cron="0 10 * * *" \
      --form cron_timezone="UTC" \
      --form active="true" \
      "https://${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/pipeline_schedules"
    
  3. Optional: Configure other notifications like Slack or Pipeline status emails with Integrations

Add a CI/CD variable to the scheduled pipeline

Only the owner of a pipeline can add a CI/CD variable with the GUI. The following steps show how a variable can be added with the GitLab API:

  1. Find the PIPELINE_ID for the created scheduled pipeline:
curl --header "PRIVATE-TOKEN: ${TOKEN}" \
  "https://${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/pipeline_schedules" \
  | jq
  
[
  {
    "id": 87,
    "description": "Daily pipeline check",
    ...
  }
]
  1. Add the variable (key and value) to the pipeline:
curl --request POST --header "PRIVATE-TOKEN: ${TOKEN}" \
--form "key=CI_SCHED_FREQ" \
--form "value=weekly" \
"https://${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/pipeline_schedules/${PIPELINE_ID}/variables"
  1. Check the result:
curl --header "PRIVATE-TOKEN: ${TOKEN}" \
"https://${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/pipeline_schedules/${PIPELINE_ID}" \
| jq

{
...
  "variables": [
    {
      "variable_type": "env_var",
      "key": "CI_SCHED_FREQ",
      "value": "weekly",
      "raw": false
    }
  ]
}
  1. Use the variable like any other CI/CD variable:
...
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule" && $CI_SCHED_FREQ == "weekly"
Andreas Vöst
Last edit
Simon Hofmann
License
Source code in this card is licensed under the MIT License.