GITLAB ci, the problem is in the sequence of jobs, how best to do it?

Viewed 19

test ci image

Welcome As you can see from the image, the CI for the experiment consists of three stages, the first stage is just "prepare" nothing special)). The second stage is the TEST itself, which consists of four jobs, is started manual depending on what is needed, usually only one of them is started. The question is in the last stage, it was thought that the notification in the telegram (bash script) should go if ONE OF the jobs of the previous stage was completed successfully. But there is no way to do this, HOW TO MAKE IT SO THAT IF ONE OF THE JOBS OF THE SECOND STAGE IS COMPLETED SUCCESSFULLY, THE JOB FROM THE THIRD STAGE IS LAUNCHED?

Here's what it looks like now:


    include:
      - project: "devops/public-resources/cicd-templates/telegram-notification"
        ref: v1.0.0
        file: "template.yml"

    stages:
      - prepare
      - test
      - notificatoin

    .common_tags: &common_tags
      tags:
        - infra-runners

    Prepare_job:
      stage: prepare
      image: alpine:latest
      script:
        - echo "prepare"
      <<: *common_tags

    test-one:
      stage: test
      image: alpine:latest
      script:
        - echo "test-one"
      needs:
        - Prepare_job
      variables:
        JOB_NAME: $CI_JOB_NAME
      when: manual
      <<: *common_tags

    test-two:
      stage: test
      image: alpine:latest
      script:
        - echo "test-two"
      needs:
        - Prepare_job
      variables:
        JOB_NAME: $CI_JOB_NAME
      when: manual
      <<: *common_tags

    test-three:
      stage: test
      image: alpine:latest
      script:
        - echo "test-three"
      needs:
        - Prepare_job
      variables:
        JOB_NAME: $CI_JOB_NAME
      when: manual
      <<: *common_tags


    test-four:
      stage: test
      image: alpine:latest
      script:
        - echo "test-four"
      needs:
        - Prepare_job
      when: manual
      variables:
        JOB_NAME: $CI_JOB_NAME
      <<: *common_tags

    # Notification jobs
    Notify Success:
      needs:
        - test-one
        - test-two
        - test-three
        - test-four
      stage: notificatoin
      extends: .telegram_notify
      variables:
        MESSAGE: |
          ✅ Successfully deployed to Production
          test: $JOB_NAME
          Text: THIS IS TEST PIPELINE
      when: on_success

    Notify Failure:
      stage: notificatoin
      extends: .telegram_notify
      variables:
        MESSAGE: |
          Text: THIS IS TEST PIPELINE
      when: on_failure

Notify Success: needs:

  • test-one
  • test-two
  • test-three
  • test-four

This works if all jobs of the second stage were completed successfully, we need that if at least one completed successfully, Notify Success was launched)

0 Answers
Related