This project has been built as a somewhat CI agnostic approach to posting build results to Slack. Some of the plugins for CI servers work great in an environment where you don't have proxy requirements but not so great when some of the tradeoffs are that you have to open the proxies up for the whole CI system (Jenkins). Granted, there are knobs you can pull, but why not also run this on an agent (again in the Jenkins case).
main.go accepts inputs via environment variables. The idea is to potentially
run this on a host or within a Docker container.
make local-docker-build will do all you need but there are other make targets available.
The following environment variables can be used. You MUST specify either HOOK_URL for incoming webhook integration
or both OAUTH_TOKEN and DEST_CHANNEL_ID for app integration which calls the Slack APIs (more flexible):
KEY TYPE DEFAULT REQUIRED DESCRIPTION
JOB_NAME String true Name of the build's job
BUILD_URL String true Direct URL to the build
BUILD_STATUS String true Status of build (e.g. currentBuild.currentResult in Jenkins)
HOOK_URL String Slack Webhook URL set via Incoming Webhooks
DEST_CHANNEL_ID String Destination Channel ID (not the name of the channel)
OAUTH_TOKEN String OAuth Token used to send message via app
LAST_BUILD_STATUS String UNKNOWN Status of last build used to provide contextual build Status
BRANCH_NAME String Name of git branch
GIT_COMMIT String Git commit hash
BUILD_TIME String Build time (e.g. durationString in Jenkins)
TRIGGERED_BY String The action which triggered the build
SKIP_IF_SUCCESS True or False Skip posting if contextual Status is success
docker run --rm=true -e OAUTH_TOKEN -e JOB_NAME -e BUILD_URL -e BUILD_STATUS -e DEST_CHANNEL_ID -e TRIGGERED_BY -e SKIP_IF_SUCCESS -e BUILD_TIME -e LAST_BUILD_STATUS -e BRANCH_NAME ci-result-to-slack
To use a Slack Bot, you'll get the OAUTH_TOKEN by following
Slack's Bot instructions. You'll want to give the bot access to
chat.postMessage by giving it the
chat:write:bot scope.
NOTE: This is not the name of the channel
To get the DEST_CHANNEL_ID (destination channel ID), you can do the following:
The Channel ID is in the URL at the end: https://${YOUR_WORKSPACE}.slack.com/messages/${DEST_CHANNEL_ID}/
If you right-click on the channel / messages, you can hit Copy Link and also see the DEST_CHANNEL_ID at the end
(e.g. https://${YOUR_WORKSPACE}.slack.com/messages/${DEST_CHANNEL_ID})
To get the HOOK_URL for Incoming Webhooks, you'll follow
Slack's Incoming Webhooks instructions.
Releases are triggered by pushing a tag. The release workflow runs
GoReleaser on any tag push, which builds binaries, publishes packages
(deb/rpm/apk), and pushes the Docker image to ghcr.io/salesforce/ci-result-to-slack.
Release notes are automatically generated from merged PRs using .github/release.yml.
git tag v1.2.3
git push origin v1.2.3This project uses semantic versioning. Choose the next version based on what has changed since the last release:
PATCH(e.g.v1.2.3) — bug fixes, dependency bumps, documentationMINOR(e.g.v1.3.0) — new backwards-compatible functionalityMAJOR(e.g.v2.0.0) — breaking changes
To see the latest tag: git describe --tags --abbrev=0
Optionally, svu can calculate the next version automatically
from conventional commits:
# Install
brew install caarlos0/tap/svu
# Show what the next version would be
svu next
# Tag and push
git tag "$(svu next)"
git push origin "$(svu next)"