Search code examples
gitlabgitlab-ci

Gitlab pipeline - run the script with a rule


I want to send a slack notification as soon as trigger the pipeline build manually.

Steps I am following:

  1. Go to your project’s CI/CD > Pipelines and select Run pipeline.
  2. Choose the branch you want to run the pipeline for.
  3. Input the variable and its value in the UI.
  4. Click on the Run pipeline button

From the documentation I see:

How the pipeline was triggered. Can be push, web, schedule, api, external, chat, webide, merge_request_event, external_pull_request_event, parent_pipeline, trigger, or pipeline. For a description of each value, see Common if clauses for rules, which uses this variable to control when jobs run.

In this init stage I want to execute a script only when I run the pipeline using the above steps

init:
  stage: init
  environment: $DEPLOY_ENVIRONMENT
  script:
    - bundle exec fastlane slack_build_start_summary
  rules:
    - if: $CI_PIPELINE_SOURCE == "trigger" // also tried with "pipeline"
      when: always

But I can't see this stage in the Gitlab pipeline stages.

I want to know which CI_PIPELINE_SOURCE ("trigger" or "pipeline" or something else?) I need to check when I trigger the pipeline manually from Gitlab using the above steps.


Solution

  • I got the answer here from the documentation

    web -> For pipelines created by using Run pipeline button in the GitLab UI, from the project’s CI/CD > Pipelines section.

    So I need to use:

    - if: $CI_PIPELINE_SOURCE == "web"