KostyaSha / github-integration-plugin

Jenkins GitHub Integration Plugin
https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Integration+Plugin
MIT License
98 stars 85 forks source link

Avoid builds for closed/merged PR #332

Open prawen opened 4 years ago

prawen commented 4 years ago

Hello,

I'm new to this plugin and really appreciate your help here.

I have configured the plugin as per the instructions provided. Client cache is set to 20. My trigger event is "Comment matched to Pattern" My webhook settings on gitlab.com sends below events a. Issue Comments b. Pull requests

Expected flow:

  1. User raises PR
  2. User makes a comment as per the pattern and the build should be triggered

Actual result: When a comment matches my pattern, build is getting triggered and the build status is being reported before and after the build. This is working as per my expectation.

Issue I'm facing

  1. When the pipeline is still running and by mistake the admin merges the PR, below flow is causing loop of builds a. Admin merges the PR b. Pipeline reports the status on the closed/merged PR c. Github PR polling log says "Change found and comment pattern matched" d. Build triggers e. Build finishes and Pipeline reports the status on the closed/merged PR f. Github PR polling log says "Change found and comment pattern matched" g. This goes in a loop. Last night I had 200 builds triggered and finally when I cancel the queued build before even running, this loop got stopped.

What I'm expecting

  1. Build should not trigger for closed/merged PR irrespective of any changes made to PR like commenting,adding approver or changing some meta data
prawen commented 4 years ago

One more observation which resulted into same issue again.

Flow:

  1. One of the user visited closed/merged PR and changed some metadata like PR template
  2. Github sent webhook event
  3. Please note the user changed only meta data like PR template and did not comment
  4. Jenkins triggered build and it went on in a loop as I described earlier. It only stopped when I cancelled the build before it even executed.
  5. In both the cases, I have observed this on closed/merged PR

Is there anyway we can ignore the build trigger if PR is closed/merged ?

prawen commented 4 years ago

@KostyaSha Can you please help ?

prawen commented 4 years ago

@KostyaSha I'm still facing this issue. Any help would be really appreciated.

KostyaSha commented 4 years ago

Probably try to add one more criteria "Pull Request Closed" that will skip PR builds.

Though Pipeline reports the status on the closed/merged PR - that's ok. That will probably change in GitHub API timestamp of repository. But then trigger will check and compare the date of the last comment. It shouldn't see new comments.
The state is saved in job directory i.e. https://github.com/KostyaSha/github-integration-plugin/blob/master/github-pullrequest-plugin/src/test/resources/org.jenkinsci.plugins.github.pullrequest.GitHubPRRepository.runtime.xml#L23 could you verify manually before and after triggering?

zhengliyuan1987 commented 3 years ago

is this issue solved? @KostyaSha