How to trigger a Jenkins build from Slack

As you know, Slack is a great product for team communication. And Jenkins help you setup a automation build (Continuous Integration). In this article, I will show the way how to use Slack Commands to trigger a Jenkins build.

Golang or Gohome T-Shirt

Buy Golang or Gohome t-shirt

In your Jenkins, you install Build Authorization Token Root Plugin, as image below

Build-Authorization-Token-Root-Plugin

 

In configuration job Jenkins, you check “trigger builds remotely” and add a token (you can get a random token here). See image below

29-01-2015 2-15-02 CH

So now, you can trigger a remote build by url:

For details, you can read https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin

In your Slack, you create a Slack Commands in Slack (e.g: /build_example).

Command textbox, type “/build_example”

URL textbox, add http://[jenkins_url]/buildByToken/buildWithParameters?job=[job_name]&token=[your_token]&[param=value]

Method combobox, choose GET. Finally, click “Save”

29-01-2015 2-24-25 CH

To test your work, go to Slack chat page, you type “/build_example” and check the result.

If you want to build with parameters from Slack (e.g /build [branch]). You need write a proxy script to handle the build. You can take a look to https://github.com/thanhson1085/slack-jenkins as a example

67071ae5-5df4-49f7-b91b-20c40b1a2cd1-medium

  • Tomek

    Hi, Thanks for the description. it’s very usefull. One thing which I’m still trying to figure out is how to send the param to the slash command which could be then use in the jenkins. For example: /build master as passing the BRANCH name to the jenkins.

  • Pingback: osx - Using Slack to start Jenkins builds - osx()

  • Jyotiprakash Nayak

    Still getting this error

    slackbot [4:51 PM] Only you can see this message

    Darn – that slash command didn’t work (error message: Timeout was reached). Manage the command at slash-command.

  • Deb

    Hi,
    Does this integration require jenkins to be exposed to the internet? How do we configure the networking between slack and jenkins?

  • tosh noway

    do you need slack admin to use this feature?