jenkinsci / ghprb-plugin

github pull requests builder plugin for Jenkins
https://plugins.jenkins.io/ghprb/
MIT License
507 stars 612 forks source link

Check if build was triggered by new commit or by comment #631

Open teojgo opened 6 years ago

teojgo commented 6 years ago

Is there a way to check if the triggered build was initiated by a new commit/pull request or by a comment matching the prescribed pattern? I would like to process the comment for a given PR. The problem is that if the build is triggered by a new commit message, the last comment is used in ghprbCommentBody which is not valid anymore.

bjoernhaeuser commented 6 years ago

Not right now. Whats your usecase? How would that look like for you?

teojgo commented 6 years ago

My usecase is the following: Whenever I submit a pull request, or update the branch corresponding to the pull request, the ghprb plugin triggers the jenkins build which runs various tests. There is a possibility that some of the tests fail. In order to rerun the failed ones or at least certain ones, I want parse the comment which in ghprbCommentBody contains the test names I would like to retry. Thus, it would be nice to have an option to know if the ghprb was actually triggered by a pull request/branch update or by a comment and let the Jenkinsfile behave differently depending on the actual trigger cause.

saikirankv commented 6 years ago

@teojgo one way to handle this is by parsing the ghprbCommentBody value, follow a standard way like "test-> testcasenames" . In execute shell split the commentBody value and get the testcase names and pass it to the test runner.

teojgo commented 6 years ago

Yes, this is exactly how I do this now. Consider now the following scenario.

  1. Make a new pull request. This will trigger the jenkins build with an empty ghprbCommentBody. In this case I take the default actions since the ghprbCommentBody does not contain anything.
  2. I make a comment which triggers a build and I parse the ghprbCommentBody in order to follow the action based on its contents.
  3. In the pull request another commit is make. This will again trigger the build but now the ghprbCommentBody is not empty but it contains whatever was put in step 2.

Since in step 3 the jenkins is triggered by a new commit, the comment of step 2 which is still contained in ghprbCommentBody is not relevant anymore. Thus, it would be nice to be able to distinguish if a build was triggered by a comment or an actual new commit. Through the ghprbCommentBody it is not possible.