YouTrack Standalone 2017.3 Help

Slack Integration (HTTP)

With the REST client implementation for the workflow API, you can use a workflow to script a push-style integration with Slack. This integration lets you post notifications to a channel in Slack when a new issue is created in a specific project. In addition, we provide a sample workflow that lets you post notifications to Slack when the priority of an existing issue is raised to High. You can modify this workflow to post notifications for any type of issue update.

This integration uses Incoming WebHooks to enable an integration between Slack and YouTrack. The YouTrack workflow sends a normal HTTP request with a JSON payload that contains the issue ID and summary.

Unlike the Slack integration over XMPP, this integration only lets you post notifications to a channel in Slack. This type of integration does not let users update issues with commands by sending direct messages to a Jabber bot.

To set up this integration with Slack, follow these steps:

  1. Add a Custom Integration to Slack
  2. Customize the Slack Integration Workflow
  3. Enable the Slack Integration Workflow in YouTrack

The basic setup described here lets you post notifications to a specific channel in Slack when an issue is created in a single YouTrack project. For more complex integrations, see Multi-channel and Multi-project Configurations.

Add a Custom Integration to Slack

This type of Slack integration is enabled on a per-project basis in YouTrack and enabled for a specific channel in Slack.

To add a custom integration:

  1. In Slack, access the channel that you want to integrate with YouTrack.

  2. From the Channel Settings menu, select Add an app or integration.
    slackIntegrationAddApp
    • The App Directory page opens.

  3. Click Build in the page header.

    slackIntegrationBuild

  4. Click Make a Custom Integration.
    slackIntegrationCustom
    • The Build a Custom Integration page opens.

  5. Select the Incoming WebHooks option.

    slackIntegrationIncomingWebhooks

  6. In the Post to Channel section, select the channel that you want to integrate with YouTrack.

  7. Click the Add Incoming WebHooks Integration button.
    • The Incoming WebHooks page displays the settings for your integration.

  8. Copy the Webhook URL and paste it into a text editor.

    slackIntegrationWebhookURL
    In the following procedure, you add this URL to your workflow rules in YouTrack.

  9. Optionally, customize the settings for your custom integration:
    slackIntegrationSettings

    Setting

    Description

    Customize Name

    Assign the integration a username.

    Customize Icon

    Upload a custom image to use for messages from this integration.

  10. Click the Save Settings button.

Customize the Slack Integration Workflow

The next step is to edit the Slack Integration workflow so it sends notifications to your channel in Slack.

This workflow contains two rules: Post New Issues to Slack and Post Priority Change to Slack. This procedure shows you how to customize the rule that posts new issues. For a detailed description of the second rule, see Update Notifications.

To customize the Slack Integration workflow:

  1. Download the Slack Integration workflow from the YouTrack Custom Workflow Repository.

  2. Open the YouTrack Workflow Editor.

  3. From the Workflow menu, select Import Workflow from File.

  4. Select the ZIP archive that you downloaded in step 1.
    • The workflow is imported into the workflow editor.

  5. Open the Post New Issues to Slack rule in the editor.

  6. Locate the doHttpPost method in the code.

  7. Replace the whole URL with the Webhook URL that you copied from your custom integration in the previous procedure.

  8. From the Workflow menu, select Upload Workflows to Server.
    • The customized workflows are uploaded to your YouTrack server.

Enable the Slack Integration Workflow in YouTrack

The last step is to attach the Slack Integration workflow to your project in YouTrack.

To enable the Slack Integration workflow:

  1. Open the project that you want to integrate with Slack.

  2. Click the Edit project link.

  3. Select the Workflow tab.

  4. From the Attach workflows list, select Slack-Integration-Generic.
    • The Slack Integration workflow is attached to your project.

    • The workflow is enabled and ready for use with your project.

When the setup is complete and the workflow is attached to your project, notification is sent to the channel when an issue is created in the project.

slackIntegrationNewIssue

In each notification, the YouTrack issue ID is set as a direct link to the issue in YouTrack.

Update Notifications

The workflow we use for this integration only posts the issue ID, summary, and the color code that indicates the issue priority. If you want to include more information, all you have to do is modify the payload to include more details about each issue.

When you post issue updates to Slack, take a selective approach and post only important updates to the channel. If you spam the channel with too many updates, important discussions are constantly interrupted by the bot.

Our sample workflow includes a rule that sends notification to the channel when the priority of an existing issue is raised to High. The YouTrack development team uses different set of conditions to push notifications to Slack when an issue is added to the current sprint. We offer this rule as an example of just one of may conditions that you can consider for sending update notifications to Slack.

Multi-channel and Multi-project Configurations

The basic setup lets you post updates from a single YouTrack project to a specific channel in Slack. However, you can easily configure this setup for more complex integration scenarios.

One Project, Many Channels

The Slack Integration workflow is scripted to support an integration between one YouTrack project and one channel in Slack. You can add custom integrations to different channels in Slack and add the Webhook URL for each channel to your workflow rules.

The following lines of code in the workflow can be customized to send notifications to multiple channels from a single project:

issue.doHttpPost("https://hooks.slack.com/services/T00000001/B000000001/XXXXXXXXXXXXXXXXXXXXXXXX", payload); issue.doHttpPost("https://hooks.slack.com/services/T00000002/B000000002/XXXXXXXXXXXXXXXXXXXXXXXX", payload); issue.doHttpPost("https://hooks.slack.com/services/T00000003/B000000003/XXXXXXXXXXXXXXXXXXXXXXXX", payload);

Many Projects, One Channel

If you want to send notifications from multiple YouTrack projects to a single channel in Slack, the setup is relatively simple.

  1. Follow the steps described here to add the URL for your Slack channel to the workflow rules.

  2. Attach this workflow to all of the projects you want to report to Slack.

Separate Projects, Separate Channels

In a slightly more complicated setup, you have multiple teams who discuss different projects in separate channels. You want to direct notifications from specific projects to the channels where each team discusses their issues.

The easiest way to handle this situation is to create separate workflows for each project and customize the rules accordingly.

To support this use case:

  1. Create a new workflow in the workflow editor. Give the workflow a name that shows its relationship to the project where it will be applied.

  2. Copy the rules from the Slack Integration workflow and past them to the new workflow.

  3. Update the Webhook URL in the workflow rules to reference the Slack channel that you want to notify in this project.

  4. Repeat steps 1 through 3 for every channel that you want to notify in each project.

  5. Upload the workflows to your server.

  6. Attach each workflow to the project for which it has been customized.

An alternative approach is to add conditional statements to your workflow rules. With conditional statements, you can identify the project that each issue belongs to and send notifications to dedicated channels in Slack. You can then attach the same workflow to all of the projects that are referenced in the workflow and update the same set of workflow rules when you want to enable Slack integration in a new project.

To support this use case, replace the single doHttpPost method with a conditional statement. Use the following sample as a guide:

if (issue.project.shortName == "Project_ 1") { issue.doHttpPost("https://hooks.slack.com/services/T00000001/B000000001/XXXXXXXXXXXXXXXXXXXXXXXX", payload); } else if (issue.project.shortName == "Project_2") { issue.doHttpPost("https://hooks.slack.com/services/T00000002/B000000002/XXXXXXXXXXXXXXXXXXXXXXXX", payload); }
Last modified: 7 March 2019