Skip to content

drone-plugins/drone-slack

Repository files navigation

drone-slack

Build Status Slack Join the discussion at https://community.harness.io Drone questions at https://stackoverflow.com Go Doc Go Report

Drone plugin for sending Slack notifications. For the usage information and a listing of the available options please take a look at the docs.

Build

Build the binary with the following commands:

go build

Docker

Build the Docker image with the following commands:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-slack
docker build --rm -t plugins/slack .

Send Slack messages Usage

To Send Slack messages use the following

Execute from the working directory:

docker run --rm \
  -e SLACK_WEBHOOK=https://hooks.slack.com/services/... \
  -e PLUGIN_CHANNEL=foo \
  -e PLUGIN_USERNAME=drone \
  -e DRONE_REPO_OWNER=octocat \
  -e DRONE_REPO_NAME=hello-world \
  -e DRONE_COMMIT_SHA=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \
  -e DRONE_COMMIT_BRANCH=master \
  -e DRONE_COMMIT_AUTHOR=octocat \
  -e [email protected] \
  -e DRONE_COMMIT_AUTHOR_AVATAR="https://avatars0.githubusercontent.com/u/583231?s=460&v=4" \
  -e DRONE_COMMIT_AUTHOR_NAME="The Octocat" \
  -e DRONE_BUILD_NUMBER=1 \
  -e DRONE_BUILD_STATUS=success \
  -e DRONE_BUILD_LINK=http://github.com/octocat/hello-world \
  -e DRONE_TAG=1.0.0 \
  plugins/slack

Please note the following new environment variables:

  • SLACK_ACCESS_TOKEN: The access token for Slack API authentication.
  • PLUGIN_CUSTOM_BLOCK: Custom blocks in JSON format to include in the Slack message.

Make sure to replace your_access_token with your actual Slack access token and adjust

If you provide an access token, it will use the Slack API to send the message. Otherwise, it will use the webhook.

Upload files to Slack

To Send Slack messages use the following

Execute from the working directory:

docker run --network host --rm \
  -e PLUGIN_ACCESS_TOKEN=your_access_token   \
  -e PLUGIN_CHANNEL=C07TL1KNV8Q \
  -e PLUGIN_USERNAME=jenkinstest003app \
  -e PLUGIN_FILE_PATH='/home/hns/test/b.txt' \
  -e PLUGIN_INITIAL_COMMENT='some start of text' \
  -e PLUGIN_TITLE='Build OK now' \
  plugins/slack

Please note the following new environment variables:

  • PLUGIN_ACCESS_TOKEN: The access token for Slack API authentication.
  • PLUGIN_CUSTOM_BLOCK: Custom blocks in JSON format to include in the Slack message.

Make sure to replace your_access_token with your actual Slack access token and adjust

If you provide an access token, it will use the Slack API to send the message.

Release Preparation

Run the changelog generator.

docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u drone-plugins -p drone-slack -t <secret github token>

You can generate a token by logging into your GitHub account and going to Settings -> Personal access tokens.

Next we tag the PR's with the fixes or enhancements labels. If the PR does not fufil the requirements, do not add a label.

Before moving on make sure to update the version file version/version.go && version/version_test.go.

Run the changelog generator again with the future version according to semver.

docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u drone-plugins -p drone-slack <secret token> --future-release v1.0.0

Create your pull request for the release. Get it merged then tag the release.