mcheriyath / slack-apigw-lambda-jenkins

Slash command to build jenkins job via apigw and lambda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

slack-apigw-lambda-jenkins

Slash command to build jenkins job via apigw and lambda

  1. Need a plugin called Build Authorization Token installed on jenkins
  2. Create a Build token for the specific job
  3. Create an API gw with a POST resource that uses this body mapping template(On POST - Method Execution > Integration Request) for Content-Type application/x-www-form-urlencoded :
{
    "data": {
        #foreach( $token in $input.path('$').split('&') )
            #set( $keyVal = $token.split('=') )
            #set( $keyValSize = $keyVal.size() )
            #if( $keyValSize >= 1 )
                #set( $key = $util.urlDecode($keyVal[0]) )
                #if( $keyValSize >= 2 )
                    #set( $val = $util.urlDecode($keyVal[1]) )
                #else
                    #set( $val = '' )
                #end
                "$key": "$val"#if($foreach.hasNext),#end
            #end
        #end
    }
}
  1. Create a lambda function named slack-jenkins with the code from this repo
  2. Use the following env variables for the lambda function:
  • JENKINS_TOKEN: Jenkins token for the remote build
  • JENKINS_URL: Base URL for your jenkins install (http://FQDNorIP)
  • SLACK_COMMAND: Name of the Slack slash-command, e.g. /rollout
  • SLACK_TOKEN: Slack token from the slash command
  1. Create a Slack slash-command that posts to your API gateway POST resource
  2. Run your slash-command with parameters /rollout , the parameter branch will be passed in to the parameterized build on Jenkins side

Future features:

  • Slack user validation
  • Use of global token for all the allowed jobs for a specific user
  • more.....

Big thanks to EonWhite

About

Slash command to build jenkins job via apigw and lambda


Languages

Language:JavaScript 100.0%