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.

Buy Golang or Gohome t-shirt
In your Jenkins, you install Build Authorization Token Root Plugin, as image below
In configuration job Jenkins, you check “trigger builds remotely” and add a token (you can get a random token here). See image below
So now, you can trigger a remote build by url:
1 |
http://[jenkins_url]/buildByToken/buildWithParameters?job=[job_name]&token=[your_token]&[param=value] |
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”
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