Bitbucket 在部署开始时发送 Slack 通知

问题描述 投票:0回答:2

我想在部署开始时向频道发送 Slack 通知。当前可用的通知涉及部署成功、失败或停止,但没有关于部署开始的通知。

是否有解决方法可以在部署开始时收到通知?

谢谢。

slack bitbucket-pipelines bitbucket-cloud
2个回答
0
投票

您可以使用 Atlassian 的 Slack 通知管道 https://bitbucket.org/product/features/pipelines/integrations?p=atlassian/slack-notify

definitions:
  yaml-anchors:

    - &slack-notify-variables
        WEBHOOK_URL: $SLACK_WEBHOOK
        # ...

    - &deploy-step
        script:
          - pipe: atlassian/slack-notify:2.0.0
            variables:
              <<: *slack-notify-variables
              MESSAGE: "Deployment to $BITBUCKET_DEPLOYMENT_ENVIRONMENT started"
          - bash deploy.sh $BITBUCKET_DEPLOYMENT_ENVIRONMENT

pipelines:
  branches:
    main:
      - step:
          <<: *deploy-step
          deployment: my-staging-environment

      - step:
          <<: *deploy-step
          deployment: my-production-environment


0
投票

如果您碰巧使用 git 标签(或愿意转向使用标签),例如

1.2.3
您可以收到标签已推送的通知,并确保您的触发器是由这些标签启动的。然后,您还可以在部署完成后收到通知,总共 2 条单独的通知。这并不适用于所有情况,但它至少可以通知您即将启动的生产级别部署(这就是我使用它的方式)。

要执行此操作:

  1. 进入“存储库设置”
  2. 选择 Slack 下的“设置”
  3. Repository-wide
    (或分支,如果您愿意)下选择
    tag created
  4. 还要确保其他
    deployment succeeded
    deployment failed
    通知仍处于选中状态。

然后,在您的管道中将其更新为:

pipelines:
  tags:
    # Matches tags like '1.2.3'
    '*.*.*':
      # ... your tag-specific pipeline steps and etc...
© www.soinside.com 2019 - 2024. All rights reserved.