Thursday, April 9, 2020

Trigger Jenkins Job from Slack | How to Trigger Jenkins Job from Slack | Slack Jenkins Integration

Jenkins job can be triggered in many ways using poll SCM, webhooks. Well, you can also trigger a Jenkins job from Slack as well.  We will be leveraging Slash commands feature from Slack.

Slash Commands allow users to invoke your app by typing a string into the message composer box.


Pre-requisites:
Make sure you have already created a channel in Slack.

Steps in Jenkins:

Create a Token for the build job you want to trigger from Slack
Go to Jenkins --> Click on the Job you would like to trigger from Slack --> Configure
Go to build triggers section.

We will be using the following URL to trigger builds from Slack
http://jenkins_dns_name/job/jobName/build?token=myToken

Allow anonymous read only access
Go to Manage Jenkins --> Configure Global security, click on Allow anonymous read only access.
Apply, Save.

Steps in Slack:

1. Go to the channel from where you would like to trigger builds.
2. Channel settings --> Click on Integrations --> Add an app



Type slash commands and add it

Click on view in app directory

Click on Add to Slack

Enter a command - single word something like /build (it should be one word no spaces or characters)

Click on Add Slash command integration
Enter Jenkins URL, like mentioned below:
http://jenkins_dns_name/job/jobName/build?token=myToken

Method as GET


and scroll down click on the check box like below

And click Save integration

Go to channel, enter the command as shown below:
/build

and press enter

Now your build job should run instantly in Jenkins.

You can watch the steps in my YouTube channel as well:

7 comments:

  1. great one.. helped it when i was stuck and getting "http_client_error" due to Jenkins Global Settings access.

    Thanks

    ReplyDelete
  2. I am facing issue with "http_client_error" in Jenkins can please help me how to resolve this issue

    ReplyDelete
    Replies
    1. Allow anonymous read only access
      Go to Manage Jenkins --> Configure Global security, click on Allow anonymous read only access.
      Apply, Save.

      Delete
  3. Hi! Can you make tutorial how to use build Jenkins pipeline with parameters from Slack?

    ReplyDelete
  4. Hi i got error /demobuildaut failed with the error "dispatch_failed" when i hit in slack, can you help?

    ReplyDelete
  5. Allow anonymous read only access
    Go to Manage Jenkins --> Configure Global security, click on Allow anonymous read only access.
    Apply, Save.

    ReplyDelete

How to Create Quality Gate in SonarQube and integrate with GitHub Actions | SonarQube Integration with GitHub Actions | Automate Code Scan using SonarQube In GitHub Actions and Force build to Fail or Pass

Pre-requisites: Make sure SonarQube is up and running Make sure Java Project is setup in GitHub SonarQube is already integrated with GitHub ...