mohamicorp / stash-jenkins-postreceive-webhook

Webhook used to notify Jenkins when commits are made to Stash
Other
138 stars 98 forks source link

Configure webhook to trigger only if push to a specific branch #58

Closed anuragkapur closed 10 years ago

anuragkapur commented 10 years ago

Is it possible to configure the webhook to be triggered if there is a change to a specific branch?

For example, I would like to trigger a jenkins job only if there is a push to a branch called "release".

mikesir87 commented 10 years ago

There is not support for this at this time. The easiest setup here would be to configure your Jenkins job to build for only certain branches.

If this isn't a potential solution for you, let me know, as I'd like to understand more of your use case. I'd prefer to keep that logic in Jenkins, as it's already there and can cause confusion for others as configuration is then occurring in two different systems.

anuragkapur commented 10 years ago

Thanks for your response. My use case is -

We commit back the version number into the pom of our project after a successful build.

So when a change to a branch, say "xyz" triggers the jenkins job, jenkins builds "release" branch again as it sees a commit in "release" which was just a release number change (which I don't want to build).

Let me explain it below:

  1. Change pushed to "release"
  2. Jenkins notified and job executes
  3. On successful job execution, the version number is updated and pushed back to "release" branch, so that "release" branch is ready for the next build
  4. Another change is now pushed to "xyz" but I don't intend this to cause execution of the Jenkins job
  5. However, jenkins sees that it has been triggered via the webhook and there is a change in "release" via step 3 which it hasn't seen before. So it builds "release"!

So because we want the version number of our pom pushed back to "release" just relying on jenkins to build "release" is not sufficient. We need to stop the webhook from firing if the change is not pushed to a pre-configured branch name.

mikesir87 commented 10 years ago

Ok. I see how that causes a problem.

Just wondering/more clarification... when you commit and push the update in Step 3, doesn't this cause another webhook notification to be fired? I'm kinda wondering how that isn't causing an infinite loop there.

anuragkapur commented 10 years ago

Infinite loop is prevented as we always commit back the version update in pom from a specific user and use the feature in the webhook to ignore specific users. I think this feature was introduced in v2 of webhook. So that works and we don't get into an infinite loop.

Do you think something could be added in the webhook to cater to the scenario I described?

Many thanks for your prompt responses.

mikesir87 commented 10 years ago

Ok. Makes sense. I'll go ahead and add this to the to-do list. I wouldn't expect it to last very long, but may be a few days. For you right now, would you prefer to whitelist or blacklist branches to trigger? Figured I'd start with one and go from there.

anuragkapur commented 10 years ago

Brilliant. Thanks a ton! A whitelist would be ideal for our use-case.

On 18 Mar 2014, at 19:09, Michael Irwin notifications@github.com wrote:

Ok. Makes sense. I'll go ahead and add this to the to-do list. I wouldn't expect it to last very long, but may be a few days. For you right now, would you prefer to whitelist or blacklist branches to trigger? Figured I'd start with one and go from there.

— Reply to this email directly or view it on GitHub.

anuragkapur commented 10 years ago

Sorry to be a pain. Roughly when do you plan to have this change available for use?

mikesir87 commented 10 years ago

No worries. I was hoping to get it done thus past weekend but got hit with bronchitis, which just knocked me out for a few days. Can we shoot for Wednesday? That work for you?

anuragkapur commented 10 years ago

Hope you feeling better! Yes, Wednesday sounds great. Thanks!

mikesir87 commented 10 years ago

You up for trying out a snapshot version? If so, I have it linked below. Go into your plugin management, uninstall the old version, then upload the jar. Don't worry... no settings will be lost during this process.

After installation, you should see the new branch options in the Advanced Configuration section. I was able to plug in both whitelist and blacklist functionalities. If you could try out your use case, I'd be happy to hear if labeling makes sense, it's easy to use, etc. Any feedback at all would be greatly appreciated.

Thanks!

http://nerdwin15.com/public/stash-webhook-jenkins-2.4.0-SNAPSHOT.jar

anuragkapur commented 10 years ago

Thanks a ton. I should be able to get this tried tomorrow. I am not the stash admin at our company, but I should be able to speak to the right person and get this tested. I shall get back to you. Thanks once again.

Anurag Kapur

@anuragkapur http://www.twitter.com/anuragkapur http://www.anuragkapur.com

On Tue, Apr 1, 2014 at 8:53 PM, Michael Irwin notifications@github.comwrote:

You up for trying out a snapshot version? If so, I have it linked below. Go into your plugin management, uninstall the old version, then upload the jar. Don't worry... no settings will be lost during this process.

After installation, you should see the new branch options in the Advanced Configuration section. I was able to plug in both whitelist and blacklist functionalities. If you could try out your use case, I'd be happy to hear if labeling makes sense, it's easy to use, etc. Any feedback at all would be greatly appreciated.

Thanks!

http://nerdwin15.com/public/stash-webhook-jenkins-2.4.0-SNAPSHOT.jar

Reply to this email directly or view it on GitHubhttps://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/issues/58#issuecomment-39250707 .

anuragkapur commented 10 years ago

Just finished looking at this in out stash installation. Works like a charm. Many thanks!

mikesir87 commented 10 years ago

Perfect! I'll go ahead and get it ready for a release on the Atlassian Marketplace. Thanks for your help!

mikesir87 commented 10 years ago

Closing this as it has been implemented and released. Thanks again for your help, suggestion, and feedback!

mozinrat commented 9 years ago

Hi @mikesir87 is it available for bitbucket as well.

metadan commented 9 years ago

Yep I would like this on bitbucket also.

Korijn commented 9 years ago

One more request vote for Bitbucket :+1:

rsarunprashad commented 7 years ago

Hi @mikesir87

I am facing an issue integrating Stash(3.2) with Jenkins. My Observation is Local git commit (local)are firing GET request to jenkins,but git push(push) is not firing . As a result ,Jenkins polling is not detecting any Changes and jenkins statys 1 commit behind.

Nagendra080389 commented 6 years ago

Does this only work with BitBucket or will it also work with Github. Because I think github plugin for jenkins does not have branch filter in webhook. Can I implement same thing in Github-plugin for jenkins too,

amanoj553 commented 2 years ago

I want to configure webhooks in GitHub for particular branch commit changes then Jenkins job needs to build.

amanoj553 commented 2 years ago

Please give me solution for above query