Skip to content
项目

关于

Create custom Slack notifications for CircleCI job statuses

开发工具

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Slack Orb CircleCI Build Status CircleCI Orb Version GitHub license CircleCI Community

Send Slack notifications from your CircleCI pipelines even easier with Slack Orb 4.0

What are Orbs?

Note: New to Slack notifications? We recommend using the native CircleCI Slack integration instead of this orb. It requires no config changes, supports user tagging, and is where we're focusing new feature development.

Share feedback or feature requests here to help us prioritize what's next.

Usage

Setup

In order to use the Slack Orb on CircleCI you will need to create a Slack App and provide an OAuth token. Find the guide in the wiki: How to setup Slack orb

Use In Config

For full usage guidelines, see the Orb Registry listing.

Templates

The Slack Orb comes with a number of included templates to get your started with minimal setup. Feel free to use an included template or create your own.

Template Preview Template Description
basic_success_1 basic_success_1 Should be used with the "pass" event.
basic_fail_1 basic_fail_1 Should be used with the "fail" event.
success_tagged_deploy_1 success_tagged_deploy_1 To be used in the event of a successful deployment job. see orb usage examples
basic_on_hold_1 basic_on_hold_1 To be used in the on-hold job. see orb usage examples

Custom Message Template

  1. Open the Slack Block Kit Builder: https://app.slack.com/block-kit-builder/
  2. Design your desired notification message.
  3. Replace any placeholder values with $ENV environment variable strings.
  4. Set the resulting code as the value for your custom parameter.
- slack/notify:
    event: always
    custom: |
      {
        "blocks": [
          {
            "type": "section",
            "fields": [
              {
                "type": "plain_text",
                "text": "*This is a text notification*",
                "emoji": true
              }
            ]
          }
        ]
      }

Dynamically Generating or Loading Importing a Custom Message

  1. Develop your code to dynamically generate a template
  2. Write the template to a local temp file
  3. Add that temp file to your $BASH_ENV
  4. Use the new env value to pass your template to the template variable (note: don't pass it to the custom parameter)
- run: ./.circleci/bin/build_template 2>&1 | tee my_template.json
- run:
    command: |
      echo 'export MY_TEMPLATE=$(jq . my_template.json)' >> $BASH_ENV
- slack/notify:
    channel: eng-deploys
    thread_id: deployment
    event: always
    template: MY_TEMPLATE

Branch or Tag Filtering

Limit Slack notifications to particular branches with the "branch_pattern" or "tag_pattern" parameter.

A comma separated list of regex matchable branch or tag names. Notifications will only be sent if sent from a job from these branches/tags. Pattern must match the full string, no partial matches. Keep in mind that "branch_pattern" and "tag_pattern" are mutually exclusive.

See usage examples.

Thread Messages

Post replies in threads with a special parameter thread_id. Including this parameter in the notify command reference stores the id of the message in a small portion of bytes in cache. Any subsequent invocation of the command with the same value for thread_id will post a reply to the initial message in a thread. Example:

- slack/notify:
      event: always
      channel: engineering
      thread_id: testing
      custom: |
        {
          "blocks": [
            {
              "type": "section",
              "fields": [
                {
                  "type": "plain_text",
                  "text": "*Tests started.*",
                  "emoji": true
                }
              ]
            }
          ]
        }
- slack/notify:
      event: always
      channel: engineering
      thread_id: testing
      custom: |
        {
          "blocks": [
            {
              "type": "section",
              "fields": [
                {
                  "type": "plain_text",
                  "text": "*Tests finished.*",
                  "emoji": true
                }
              ]
            }
          ]
        }

Scheduled Message

Set the scheduled_offset_seconds special parameter to a number of seconds if you want to post a scheduled message. Example:

- slack/notify:
    event: always
    scheduled_offset_seconds: 30
    custom: |
      {
        "blocks": [
          {
            "type": "section",
            "fields": [
              {
                "type": "plain_text",
                "text": "*This is a text notification*",
                "emoji": true
              }
            ]
          }
        ]
      }

GovSlack Support

Set the api_domain parameter to specify which Slack API domain to use. Use slack.com for regular Slack workspaces (default) and slack-gov.com for GovSlack workspaces.

- slack/notify:
    event: always
    api_domain: slack-gov.com
    custom: |
      {
        "blocks": [
          {
            "type": "section",
            "fields": [
              {
                "type": "plain_text",
                "text": "*This is a text notification to GovSlack*",
                "emoji": true
              }
            ]
          }
        ]
      }

FAQ

View the FAQ in the wiki

Contributing

We welcome issues to and pull requests against this repository!

For further questions/comments about this or other orbs, visit CircleCI's orbs discussion forum.

探索相关项目

加载中…