gitlab ci pipeline auto trigger jobs

1.7k Views Asked by At

We have a gitlab ci pipeline which has multiple stages and jobs. First, I have a config push stage and I have a job that sends config to 6 different clusters. Then I have many different stages for deployment. In the last stage, I have a stage that notifies the slack channel. It has 2 different jobs.

What I want to do is exactly this:

After running any of the 3 specific config push jobs on the first stage, I want to auto-trigger the slack notification jobs on the announce stage.

enter image description here

Any job marked with green in the config-push stage visible in the drawing should auto-trigger both jobs in the announce slack.

my announce-slack job is :

slack-config-push-announce:
  stage: announce
  extends: .slack_announce
  only:
    - master
  variables:
    EMOJI_LEFT: ":config-push:"
    EMOJI_RIGHT: ":config-push:"
    MESSAGE: "Config Push"
    GITLAB_SLACK_DEPLOY_CHANNEL: $GITLAB_SLACK_DEPLOY_CHANNEL

Also, when I trigger any of the config push jobs for the 2nd time, I want the announce jobs to run again, but it doesn't trigger again because it works once.

thanks in advance for the help...

1

There are 1 best solutions below

1
On

I think the only way to do this is to have a 1:1 match of announce jobs to config push jobs. You can use needs: to make the announce jobs start right after the specified job(s) finish, even if there are other stages inbetween the config push and the stage for the announcement.

stages:
  - one
  - another_stage
config-push a:
  stage: one
  # ...
config-push b:
  stage: one
  # ...
config-push c:
  stage: one
  # ...

slack-announce/a:
  stage: .post
  needs: ["config-push a"]
  # ...
slack-announce/b:
  stage: .post
  needs: ["config-push b"]
  # ...
slack-announce/c:
  stage: .post
  needs: ["config-push c"]
  # ...

Alternatively, you may opt to just use after_script: on your config push jobs to send the notifications.

config-push a:
  after_script:
    - notify-slack "pushed a"