Search code examples
jenkinscontinuous-deploymentslack

How to pass the additional parameter of slash command to jenkins job


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