PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 28, 2022

[FIXED] How to pass the additional parameter of slash command to jenkins job

 September 28, 2022     continuous-deployment, jenkins, slack     No comments   

Issue

Let's say I want to create a slash command with the flexibility to define the component as tag name which will be used for deployment.

eg: /dev-deploy comments v1.0.0

I have added the slash command as well as set the parameterized URL in

http://host/buildByToken/buildWithParameters?job=dev-deployment&token=test

All the other commands data is present in JSON object how can I access that data and pass it as a parameter to shell script which is executed when the build is triggered.


Solution

The slash command from Slack is sending a POST request to your URL. This request contains a property named text, which in your example would be "comments v1.0.0". To extract the tag you would need to parse it.

I would recommend to use some simple script (e.g. PHP) to receive the POST request, parse it (maybe also do some security checks) and then start the job with a shell command.

I am not sure what JSON object you are referring to. The slash command does not send any JSON. So maybe your question is missing some vital information? If so please add.

Here is an example of the POST request (from the official Slack documentation):

token=gIkuvaNzQIHg97ATvDxqgjtO
team_id=T0001
team_domain=example
enterprise_id=E0001
enterprise_name=Globular%20Construct%20Inc
channel_id=C2147483705
channel_name=test
user_id=U2147483697
user_name=Steve
command=/weather
text=94070
response_url=https://hooks.slack.com/commands/1234/5678


Answered By - Erik Kalkoken
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing