JMeter / Selenium WebDriver – How To Trigger Automated Test Execution From Slack

Overview:

We use Slack in our organization. You might also be using Slack for communicating information among the team members in your org. Slack is a great tool and it keeps everyone up to date and reduces unnecessary emails. Particularly automated status, build notifications etc which might flood your inbox. I have already shared an article on posting automated test results in Slack on a specific channel here.

Lets see how we could trigger an automated test suite execution in your Jenkins/CI tool.

Jenkins/CI:

The very first assumption is you have been using some CI tool like Jenkins. I also assume that the tool exposes some kind of API to trigger/schedule a build/job. Here I use Jenkins. You can get the high level idea and implement something similar if you use other tools.

The second assumption is you have a job in Jenkins configured properly which runs just fine when you trigger it manually.

Creating New User:

Lets start with creating a new user in Jenkins for slack to use. Make a note of the API token.

Screenshot from 2018-04-21 12-02-07

The assumption is this slack user has enough access to trigger the job.

Execute the below CURL command to verify if the user is able to invoke the job.

This is the format of the url. Replace the content within [ ] with appropriate information

curl -X POST http://[user:token]@[jenkins-host-with-port]/job/[job-name]/build

In my case, I tried as shown here.

curl -X POST http://slack:c1c54d626f6a11fbc98ed795ec8862bc@10.11.12.13:8080/job/TEST_ATOMATION_GURU_SLACK_JOB_DEMO/build

Slack – Slash Command:

To invoke the above Jenkins job, we would be using Slack’s slash commands. So whenever you type something after a slash – for ex: ‘/weather‘ – Slack will treat it as a command and can respond to the command. So, for that example, Slack can be configured to provide a weather report for your city.

Screenshot from 2018-04-21 12-19-49

  • Go to your Slack configuration to add Slash configuration.
  • I am going to create a smoketest command – so my team can trigger a smoke test from slack to check the health of the application.

Screenshot from 2018-04-21 12-20-25

  • Add the integration setting as shown here. Provide the URL which we need to call to trigger the jenkins job.

Screenshot from 2018-04-21 13-28-33

  • Select the auto complete help

Screenshot from 2018-04-21 13-31-54

  • Once the configuration is done, You can verify immediately in your Slack. Just type ‘/s’ – you could see the ‘smoketest’ command

Screenshot from 2018-04-21 13-38-48

  • Invoke the command – Check if Jenkins is able to trigger the job.

Screenshot from 2018-04-21 12-27-12

  • If the Job requires a parameter, Use the below URL format to invoke the job with Default parameters.
curl -X POST http://[username:token]@[jenkins-host-with-port]/job/[job-name]/buildWithParameters
  • If you need to pass any specific parameter, Simply append the variable and value in the parameter.
curl -X POST http://[username:token]@[jenkins-host-with-port]/job/[job-name]/buildWithParameters?ENVIRONMENT=PROD
  • To get the status/result of the job, job should be configured to post the results back to Slack. You could check an article on that here.

Note:

  • To make the above approach work, Your Jenkins server should be accessible by Slack. Ensure that it is not blocked by the firewall.

Summary:

Slack commands are very useful and come in handy to get information or to trigger something which you might do frequently. By doing this, any non-technical user in the team could make you use of your automated test scripts by directly calling the slash command.

Happy Testing & Subscribe 🙂

 

Share This:

16 thoughts on “JMeter / Selenium WebDriver – How To Trigger Automated Test Execution From Slack

    1. You might be able to hit. The question is if Slack is able to hit? it will be able to only if the jenkins is exposed in the internet.

  1. Hi vlns,

    It seems that my Jenkins server is not exposed in the Internet. I will try to find how to expose it then I will return to you result.

    Thanks for your support.

  2. @Hien: You should be registered a cloud service as Google Cloud/ AWS then install Jenkins server on it – you’ll have public IP to trigger job.

  3. I am seeing below error when i trigger the job by using slash command from slack

    Darn – that slash command didn’t work (error message:
    400_client_error
    ). Manage the command at text.

    What could be the reason for this error and how to resolve this?

  4. Initially i got invalid_url , then i have given my companies jenkins end point along with https with -v to ignore the certificates. Tested the url in cmd and its working fine. The jenkins job has been kicked off. But when i use the same url in slack config, getting this error :
    Darn – that slash command didn’t work (error message: Failure when receiving data from the peer). Manage the command at text

    1. Do note that it might work in your commandline as you are in the same network. It does not mean that slack can hit your Jenkins. Looks like a firewall issue to me. Please work with Jenkins administrator.

  5. @vIns I tried the same steps but getting the following error:
    failed with the error “invalid_url”
    Also I tried to fix this using ngrok but no luck.
    Can you please explain me bit more?
    Thanks

    1. Before trying via slack, did you try by sending a HTTP request yourself to trigger jenkins job? That will confirm if it is a valid URL or not!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.