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