stash-jenkins-postreceive-webhook icon indicating copy to clipboard operation
stash-jenkins-postreceive-webhook copied to clipboard

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

Open visualphoenix opened this issue 10 years ago • 5 comments

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.

visualphoenix avatar Apr 02 '14 03:04 visualphoenix

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>

mikesir87 avatar Apr 02 '14 03:04 mikesir87

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 avatar Apr 02 '14 03:04 visualphoenix

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()

visualphoenix avatar Apr 02 '14 03:04 visualphoenix

@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.

loa avatar Jun 30 '14 10:06 loa

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

benwicks avatar Mar 20 '17 14:03 benwicks