12

In an ideal world our less tech-knowledgeable employees could just use a Slack command to run a job and get the results slacked back to them, negating the use of the Jenkins GUI. I found Start a build in Jenkins using a Slack Command on GitHub, but it's got a few limitations including that it seems to require a 1:1 ratio Heroku instance to Jenkins job, which isn't great for our purposes.

My thought is to have people use a singular command like /jenkins, and use parameters after it that will be parsed by one job, and used to kick off others downstream. That keeps us to one slack command / one instance, but still gives us all the flexibility we need.

The issue falls in getting the parameters to Jenkins. I'm picturing something like the following workflow;

  1. User types /Jenkins job2 param1 param2 in Slack. This is calling an umbrella job that will parse the parameters to find out what to run.

  2. Command is somehow sent to the umbrella jenkins job. Heroku instance, direct integration, w/e.

  3. Umbrella job receives job2 param1 param2 as a string. (Perhaps as the value of a single parameter, perhaps pre-split into multiple fields)

  4. Umbrella job splits the string if it hasn't already been done, and figures out that the user wants job2 run, using parameters param1 and param2.

  5. Umbrella job does a buildjob to run the downstream job as called, which will Slack back to the user their results.

It's steps 2-3 that are tripping me up. How can I pass a string (with spaces!) from Slack to my Jenkins job?

If my entire premise is wrong I'm also open to having my frame challenged.

5

The plugin you found doesn't have a 1:1 ratio between Heroku instance with build jobs since it takes the job name as parameter, so you should be able to run any number of jobs from a single Heroku instance.

As for passing a space in a job parameter, the word split is made on spaces so quoting won't change anything. You could possibly try to use the HTML spacing character %20 and see if it works?

Personally I would try to use the plugin to run the correct job with the associated parameters directly instead of going through filtering jobs.

  • 1
    To be exact, the split on spaces is made a few lines above your link, I didn't dig enough to confirm or not it will split on all spaces, but it sounds like it wilk – Tensibai May 4 '17 at 19:30
  • You are correct, it's split on spaces by this line github.com/joshdholtz/jenkins-slack-command/blob/master/… so it won't matter if there are quotes or not around the parameters – Michael Pereira May 4 '17 at 19:35
  • Yep parameters are looped over and split again on = this will break if a value contain spaces, using %20 may work when posted to slack, but it has to be tested because I've no idea how Jenkins or slack may parse or keep them – Tensibai May 4 '17 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.