Integrating ISPW with Slack

Integrating ISPW with Slack

Note: If you don’t already have your own Slack Account, you can get one for free at https://slack.com/.

  1. Add an Incoming WebHook custom integration to your Slack
    1. To do this go to https://yourteam.slack.com/apps/build/custom-integration (replace ‘yourteam’ with your Slack team)
    2. Click “Incoming Webhooks”
    3. Select a channel (we will be working with ‘#general’ for our example)
    4. Click “Add Incoming WebHooks integration”
    5. For now, scroll all the way to the bottom and select “Save Settings”
    6. Scroll to Webhook URL and click “Copy URL” and store this for later in your favorite text editor
  2. Decide on a format for your Slack message
    1. For our example, we have three components to our Slack API call: text, username, and icon_emoji
      1. ‘text’ is the content of the message that will be posted in slack. In our example, this is “Promotion of tasks in TEST35813 at level dev1 has completed”
      2. ‘username’ is the name that will appear to post the message. In our example, we use “ISPW”
      3. ‘icon_emoji’ is the icon that will show up ahead of the message. In our example, we use “:elephant:”
    2. Build the Slack JSON Body
      1. Slack takes message input in the form of JSON, which follows a name:value pairing format
      2. For our example, our JSON looks like this:
        slack-text-code
      3.  This block of JSON tells slack to post the message “Promotion of tasks i TEST35813 at level dev1 has completed” from a bot named “ISPW” and to use the icon elephant emoji
      4. Feel free to tweak any of this message and then save the JSON for later. We will use it in our API call into CES (Click here for more info on Slack APIs)
  3. Build the API call
    1. We assume at this point you have defined an ISPW release with one or more tasks in it to test with, but if not, go get one ready now
    2. Promoting a release is done by POSTing to http://YOURCES:YOURPORT/ispw/{srid}/releases/{releaseId}/tasks/promote?level={level}
      1. Tweak this URL to fill in the host and port where Compuware Enterprise Services is hosted. These replace ‘YOURCES’ and ‘YOURPORT’ (to continue our example, we will use “localhost:48226”)
      2. Replace {srid} with the instance of ISPW you are using (to continue our example, we will use “w3t”)
      3. Replace {releaseId} with the release you wish to promote (we will continue with “TEST35813”)
      4. Replace {level} with the level of tasks you want to promote from (we will be promoting all tasks at dev1)
        Note: if you have a different releaseId or level then we are using, you will want to update your Slack message to reflect this
      5. Save this URL as we will use it in our curl
    3. CES requires an Authentication Token to be passed in the header of the request
      1. These tokens are created at http://CES:PORT/compuware/jsp/settings/tokens.jsp. If you don’t have one already, create one now
      2. This token is used in the header like so, “Authorization: TOKEN”, or for our example, “Authorization: 8cd92475-6383-4b42-a792-619a16cb8867”
      3. Save this Header as we will use it in our curl
    4. CES requires a Content-Type header to be passed in as well
      1.  This will be “Content-Type: application/json”
      2. Save this Header as we will use it in our curl
    5. CES requires a JSON Body to outline what notifications should cause Slack to post a message
      1. This JSON Body, at a minimum, will have an “events” array (you also need a “runtimeConfiguration”. If you don’t know what this is, see your ISPW Administrator)
      2. For our example, our JSON Body will look like this:
        slack-runtime-config-code
      3. For a Slack integration, our “events” array will contain one or more events which each consist of a “name”, a “url”, and a “body”
        1. For our example, we use the event name “Completed”. This event is triggered when the promote completes successfully
        2. Replace the https://hooks.slack.com URL with the Slack WebHook URL we saved in 1-f
        3. “body” is the JSON Body CES will send to Slack when this event occurs. This was created earlier, in 2-b
          1. Update the “body”:” ” with your Slack JSON
      4. Save this JSON Body as we will use it in our curl
  4. Put it all together
    1. Now that we have our API URL, API Headers, and our API Body, we are ready to make our API call
    2. For our example, we will show curl and Advanced REST client, which is a chrome extension that lets you visually build your API call and send it
    3. First we will show a commented version of the call and then we will show our actual call used

Curl with Comments
slack-curl-with-comments-code

Actual Curl
slack-curl-h-code

Advanced REST client example usage:

hipchat_img1

End Result:

slack_img2