Ember CLI Deploy Slack Plugin
ember-cli-deploy-slack is an ember-cli-deploy plugin designed to send deployment notifications to Slack. It integrates deeply into the `ember-cli-deploy` pipeline, providing hooks to send customizable messages for various stages such as `didDeploy` and `didFail`. The current stable version is 2.0.0, which includes updated dependencies and Node.js version requirements. As an Ember CLI Deploy plugin, its release cadence is typically aligned with the broader Ember ecosystem and major dependency updates. Its key differentiator is its seamless integration with the `ember-cli-deploy` context, allowing dynamic message generation using deployment-specific data, and leveraging `node-slackr` for flexible Slack message formatting.
Common errors
-
Slack notification failed: Invalid webhook URL
cause The `webhookURL` configured in `config/deploy.js` is either missing, malformed, or has been revoked in Slack.fixVerify the `webhookURL` in your `config/deploy.js` file (or the environment variable it reads from), ensuring it's a valid and active Slack incoming webhook URL. Check for typos or missing parts of the URL. -
TypeError: slack.notify is not a function
cause A custom hook function (e.g., `didDeploy`, `didFail`) is not correctly returning a function that accepts `slack` as an argument before attempting to call `slack.notify`.fixEnsure your custom hook functions follow the pattern `function(context) { return function(slack) { /* call slack.notify here */ }; }`. The `slack` object is only available in the *inner* function.
Warnings
- breaking Version 2.0.0 introduces breaking changes by updating internal dependencies and raising the minimum Node.js version requirements. Earlier Node.js versions (e.g., Node 12) are no longer supported.
- gotcha Sensitive configuration values like `webhookURL` should be managed via environment variables and *not* hardcoded directly into `config/deploy.js`.
Install
-
npm install ember-cli-deploy-slack -
yarn add ember-cli-deploy-slack -
pnpm add ember-cli-deploy-slack
Imports
- slack configuration
import Slack from 'ember-cli-deploy-slack'
ENV.slack = { webhookURL: '...' } - Custom Hook Functions
ENV.slack.didDeploy = 'Deployment complete!'
ENV.slack.didDeploy = function(context) { return function(slack) { return slack.notify({ text: '...' }); } }
Quickstart
// config/deploy.js
module.exports = function(deployTarget) {
var ENV = {
slack: {
webhookURL: process.env.SLACK_WEBHOOK_URL ?? 'YOUR_SLACK_WEBHOOK_URL', // Use env var for security
channel: '#deployments',
username: 'EmberDeployBot',
iconEmoji: ':rocket:',
// Example of a custom message for successful deployments
didDeploy: function(context) {
return function(slack) {
const projectName = context.project.name();
return slack.notify({
text: `:white_check_mark: ${projectName} deployed to ${deployTarget}!`,
attachments: [
{ text: `Revision: ${context.revisionData.revisionKey}` }
]
});
};
}
}
};
if (deployTarget === 'production') {
ENV.slack.channel = '#production-deploys';
}
return ENV;
};
// Terminal
// $ ember install ember-cli-deploy-slack
// $ SLACK_WEBHOOK_URL="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" ember deploy production