Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow webhook to trigger on Tags #166

Open
helterscelter opened this issue Feb 2, 2016 · 6 comments
Open

allow webhook to trigger on Tags #166

helterscelter opened this issue Feb 2, 2016 · 6 comments

Comments

@helterscelter
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

@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
Copy link

ryanewtaylor commented Feb 16, 2017

@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
Copy link

ryanewtaylor commented Feb 17, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants