mohamicorp / stash-jenkins-postreceive-webhook

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

Add eligibility filter to allow triggering jenkins on new branch creation push event #61

Open visualphoenix opened 10 years ago

visualphoenix commented 10 years ago

Hey there.

Currently the stash-jenkins-postreceive-webhook does not trigger jenkins if a new branch was created and pushed but that branch had no new commits. It might be possible to identify a new branch creation from a push event by checking for a RefChangeType of ADD from RefChange.getType().

Background:

As part of the git-flow release process, a release/X.Y.Z branch is cut from develop. If develop was stable, possibly no commits are necessary to release/X.Y.Z. In this case we would want jenkins to build a release candidate artifact from this new branch creation event (even though no new commit was made) and auto-deploy it for testing. Possibly develop commits get autodeployed to a dev environment and release/* commits get autodeployed to a qa environment.

mikesir87 commented 10 years ago

Great suggestion! I'd have to look for the right event to listen to, but I imagine this wouldn't be too difficult to pull off.

Do you know if Jenkins will perform a build on a new branch without a change in the current commit hash? I haven't tried, so don't know. If Jenkins won't build, then notifying Jenkins won't help anyways.

If I could have you test it out by opening your browser to the URL below right after cutting a new branch (still with no new commits). Let me know if a Jenkins build actually fires. You can check the "Git Polling Log" for the Jenkins build to see if it actually checked for updates or not. If no build was performed, we'll need to get the Git Plugin to be updated too.

http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository - either SSH or HTTP>

visualphoenix commented 10 years ago

I'm currently working around this by manually triggering jenkins to build. In the above example case, jenkins properly finds the new repository and builds the release candidate. It would be handy if it worked automatically.

visualphoenix commented 10 years ago

https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/blob/54fa2568bf113ab0a2fa3e06eeb90990abfe0252/src/main/java/com/nerdwin15/stash/webhook/RepositoryChangeListener.java seems to indicate that RepositoryRefsChangedEvent is notified for RepositoryPushEvent and i believe RepositoryPushEvent has the RefChange.getType()

loa commented 10 years ago

@visualphoenix: I'm trying to figure out what is needed to be done in issue #71.

I was unable to reproduce your issue, for me Jenkins is triggered when pushing a new branch with same head as master.

benwicks commented 7 years ago

How would you prevent Jenkins from triggering a build if a new branch was created but no commits were made to the branch yet?