Giter Site home page Giter Site logo

shivam175 / slack-orb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from circleci-public/slack-orb

0.0 1.0 0.0 224 KB

Create custom Slack notifications for CircleCI job statuses

Home Page: https://circleci.com/orbs/registry/orb/circleci/slack

License: MIT License

Shell 100.00%

slack-orb's Introduction

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

Easily integrate custom Slack notifications into your CircleCI projects. Create custom alert messages for any job or receive status updates.

Learn more about Orbs.

Usage

Example config:

version: 2.1

orbs:
  slack: circleci/[email protected]

jobs:
  build:
    docker:
      - image: <docker image>
    steps:
      - slack/<command>

[email protected] from the circleci namespace is imported into the config.yml as slack and can then be referenced as such in any job or workflow.

Commands

Notify

Notify a slack channel with a custom message at any point in a job with this custom step.

Parameter Type Default Description
webhook string ${SLACK_WEBHOOK} Either enter your webhook value or use the CircleCI UI to add your token under the SLACK_WEBHOOK environment variable
message string Your job on CircleCI has completed. Enter a custom message to send to your Slack channel
mentions string false Comma-separated list of Slack User or Group (SubTeam) IDs (e.g., "USER1,USER2,USER3"). Note: these are Slack User IDs, not usernames. The user ID can be found on the user's profile. Look below for information on obtaining Group ID. For here, channel or everyone just write them.
color string #333333 Hex color value for notification attachment color
author_name string Optional author name property for the Slack message attachment
author_link string Optional author link property for the Slack message attachment
title string Optional title property for the Slack message attachment
title_link string Optional title link property for the Slack message attachment
footer string Optional footer property for the Slack message attachment
ts string Optional timestamp property for the Slack message attachment
include_project_field boolean true Condition to check if it is necessary to include the Project field in the message
include_job_number_field boolean true Whether or not to include the Job Number field in the message
include_visit_job_action boolean true Whether or not to include the Visit Job action in the message
channel string If set, overriding webhook's channel setting

Example:

version: 2.1

orbs:
  slack: circleci/[email protected]

jobs:
  build:
    docker:
      - image: <docker image>
    steps:
      - slack/notify:
          message: "This is a custom message notification" # Optional: Enter your own message
          mentions: "USERID1,USERID2," # Optional: Enter the Slack IDs of any user or group (sub_team) to be mentioned
          color: "#42e2f4" # Optional: Assign custom colors for each notification
          webhook: "webhook" # Optional: Enter a specific webhook here or the default will use $SLACK_WEBHOOK

Custom Message Example

Refer to Slack's Basic message formatting documentation for guidance on formatting notification messages.

Status

Send a status alert at the end of a job based on success or failure. This must be the last step in a job.

Parameter Type Default Description
webhook string ${SLACK_WEBHOOK} Either enter your webhook value or use the CircleCI UI to add your token under the SLACK_WEBHOOK environment variable
success_message string ๐ŸŽ‰ A $CIRCLE_JOB job has succeeded! $SLACK_MENTIONS Enter your custom message to send to your Slack channel
failure_message string ๐Ÿ”ด A $CIRCLE_JOB job has failed! $SLACK_MENTIONS Enter your custom message to send to your Slack channel
mentions string Comma-separated list of Slack User or Group (SubTeam) IDs (e.g., "USER1,USER2,USER3"). Note: these are Slack User IDs, not usernames. The user ID can be found on the user's profile. Look below for information on obtaining Group ID.
fail_only boolean false If set to true, successful jobs will not send alerts
only_for_branches string If set, a comma-separated list of branches for which to send notifications
include_project_field boolean true Whether or not to include the Project field in the message
include_job_number_field boolean true Whether or not to include the Job Number field in the message
include_visit_job_action boolean true Whether or not to include the Visit Job action in the message
channel string If set, overriding webhook's channel setting

Example:

version: 2.1

orbs:
  slack: circleci/[email protected]

jobs:
  build:
    docker:
      - image: <docker image>
    steps:
      # With fail_only set to `true`, no alert will be sent in this example. Change the exit status on the next line to produce an error.
      - run: exit 0

      - slack/status:
          mentions: "USERID1,USERID2" # Optional: Enter the Slack IDs of any user or group (sub_team) to be mentioned
          fail_only: true # Optional: if set to `true` then only failure messages will occur.
          webhook: "webhook" # Optional: Enter a specific webhook here or the default will use $SLACK_WEBHOOK
          only_for_branches: "master" # Optional: If set, a specific branch for which status updates will be sent. In this case, only for pushes to master branch.

Status Success Example Status Fail Example

Dependencies / Requirements

Bash Shell

Because these scripts use bash-specific features, Bash is required. Bash is the default shell used on CircleCI and the Orb will be compatible with most images. If using an Alpine base image, you will need to call apk add bash before calling this Orb, or create a derivative base image that calls RUN apk add bash. If Bash is not available, an error message will be logged and the task will fail.

cURL

cURL is used to post the Webhook data and must be installed in the container to function properly.

Help

How to get your Slack Webhook

Full instructions can be found at Slack: https://api.slack.com/incoming-webhooks

  1. Create Slack App. This will also be the name of the "user" that posts alerts to Slack. You'll be asked for which Workspace this app belongs to.
  2. In the settings for the app, enable Incoming Webhooks
  3. In the left hand panel of your Slack app settings, under Features click Incoming Webhooks
  4. Click Add New Webhook to Workspace. You will be asked to pick a channel for the webhook here.
  5. Done! A webhook URL will be created.

How To Get Your Group ID

  1. Navigate to https://api.slack.com/methods/usergroups.list/test
  2. Select the correct application under "token"
  3. Press "Test Method"
  4. Find your group below and copy the value for "ID"

What to do with Slack Webhook

You can implement the Webhook in one of two ways, either as an environment variable, or as a parameter.

  1. In the settings page for your project on CircleCI, click Environment Variables. From that page you can click the Add Variable button. Finally, enter your webhook as the value, and SLACK_WEBHOOK as the name.
  2. You can enter the Webhook for the individual status or alert by entering is at the webhook parameter, as shown above.

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.

slack-orb's People

Contributors

7wikd avatar felicianotech avatar fumikony avatar gprestes avatar gsaslis avatar iynere avatar kyletryon avatar minamijoyo avatar nithinrg avatar rail44 avatar rmacklin avatar ryym avatar samsalisbury avatar scwheele avatar stig avatar thomasmost avatar tommybo-entur avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.