mohamicorp / stash-jenkins-postreceive-webhook

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

allow webhook to trigger on Tags #166

Open helterscelter opened 8 years ago

helterscelter commented 8 years ago

I'm trying to trigger jenkins based on new tags in my repo, by using "refs/tags/" and "tags/" as my branch options in the plugin config.

I see something about this is mentioned here: https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/blob/master/src/main/java/com/nerdwin15/stash/webhook/RepositoryChangeListener.java#L54

I've spent literally 4 seconds looking through the plugin code and stash api, so I don't pretend to understand what this does. but this seems to imply that triggering based on tags would not occur?

is it possible to setup this plugin/stash to notify jenkins for new tags?

munkyboy commented 8 years ago

it doesn't look like this is possible at the moment.

at some point, BranchEligibilityFilter asks for the lists of all branches in a chageset. branches in this case are things that start with refs/heads/ whereas tags start with refs/tags/

https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/blob/master/src/main/java/com/nerdwin15/stash/webhook/service/ConcreteBranchEvaluator.java#L34

paulcichonski commented 8 years ago

I was struggling with this trying to get my builds to only trigger on new tags and when the PR "trigger build" button is pressed. I've found a sort of hackish workaround below:

Set Advanced Configuration > Branch Options > Ignore From to a single wildcard: *. Which tells the hook to skip all branches, but since it doesn't process tags in that filter, it still triggers on tags. With this configuration the PR "trigger builds" button will continue to work as well.

ryanewtaylor commented 7 years ago

We could definitely use the capability to trigger builds on branches and tags. The basic workflow we desire is to be able to setup up two jenkins jobs.

One job simply runs any build and test scripts on our specified branch (e.g., master) anytime there are new commits. This is pretty straight forward simply by specify which branches to trigger a build in the "build from:" options. This helps to verify we have working code when any commits are made.

The second job is used to package and deploy released code. We would like to define a release as any commit with a tag (e.g., v1.0.1). This is possible with the workaround described by @paulcichonski which is to specify "*" in the "Ignore From" options.

However, the workaround appears to disallow the first option.

@mikesir87 , is this something that will eventually be added to this plugin?

paulcichonski commented 7 years ago

@ryanewtaylor I think you should be able to use Build From instead of ignore from to achieve both types of builds. For example if you set Advanced Configuration > Branch Options > Build from to master, it will build master changes and tags.

Its been a while since I've dug into this so I could be wrong.

ryanewtaylor commented 7 years ago

@paulcichonski I tested that configuration and it does not appear to trigger the jenkins job. I think a helpful configuration for this plugin would be to be able to specify which branches and tags you want to include, e.g.,

build from: master develop refs/origin/tags

Similar to what is specified in Jenkins

ryanewtaylor commented 7 years ago

I have managed to get this to work for both my use cases with the following setup.

Configure Stash / Bitbucket Server

Select Advanced Configuration > Branch Options > Build All. Do not specify any branches. This will skip the whitelist and blacklist checks so that all new commits and tags send the required Jenkins notification.

Set up a Jenkins Job for Tags

In the job set refspec to +refs/tags/*:refs/remotes/origin/tags/*. Set branch specifier to **/tags/*. This will configure the job so it only responds to new tags.

Set up a Jenkins Job for master

In the job clear refspec if not already cleared. Set branch specifier to origin/master. This will configure the job so it only responds to changes on the origin/master branch.

Helpful resource: http://erics-notes.blogspot.be/2013/05/jenkins-build-latest-git-tag.html