3

I am familiar with Jenkins Pull Request Builder and I had set up a freestyle job with it to build my project based on the comment that authorized user put. (For example test in prod) in the past.

Now I am trying to use a Jenkins 2.0 with github organization plugin for one of my project.

this is the scenario:

  1. A User is making a PR to master(or some other sensitive branch)
  2. A test is going to get run automatically.
  3. After the test past, an authorized user needs to go to the PR and put a comment Deploy to test environment and then a jenkinsfile that was waiting for this input needs to get trigger.

I just dont know how to do the step 3. how do I make jenkins pipeline job listen for comments in github repo pull requests? the Jenkins documentation is not really clear about the input from user part.

I read this thread answer but the documentation about the Gates approval is really limited.

Community
  • 1
  • 1
click
  • 447
  • 1
  • 7
  • 25
  • I have a similar use-case. 1 diff is I have multi-branch pipeline config. I have a GitHub WebHook talking to AWS Lambda (instead of directly to Jenkins Server). But that is having issues since the Jenkins isn't receiving Github events anymore and hence new PR branch isn't discovered -> this prevents me from triggering build on the Jenkins jobs using the Lambda function. Any idea how to go about this? How did you solve your problem @click – Chaitanya Bapat Mar 07 '20 at 07:54

1 Answers1

1

I know this is super late, but here's some info for future Googlers:

I have a Github webhook that sends the event to a Lambda function that will parse the event for a specific comment string, then create an HTTP POST request for the Jenkins job, which is configured to allow builds to be triggered remotely.

So: open PR > comment on PR 'Deploy to test environment' > webhook sends to AWS APIGateway > AWS SNS topic > AWS Lambda > parse the event for comment > If comment matches, create HTTP POST > Jenkins receives request and runs job

There's a lot of documentation on this, but none of it together, so here are the resources that I used:

Regarding allowing jobs to be triggered remotely: https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

Using Github to trigger Lambda function: https://aws.amazon.com/blogs/compute/dynamic-github-actions-with-aws-lambda/

Github API. You will want to pay particular attention to the Issues API: https://developer.github.com/webhooks/

Jacob
  • 890
  • 6
  • 16
  • I was able to figure this out (trigger Jenkins build if specific comment is made on the PR) Issue I am facing is this works only if Jenkins has already discovered the PR branch. Unfortunately, whenever I create a PR Jenkins is unable to discover that branch. Hence the lambda isn't able to trigger a build on that PR branch. @Jacob any idea what am I missing? – Chaitanya Bapat Mar 05 '20 at 22:44