Giter Club home page Giter Club logo

stash-jenkins-postreceive-webhook's Introduction

Maintenance and support for this plugin has now been taken over by Mohamicorp. Please use our issue tracker here to create any issues or support requests.


Bitbucket Server Webhook for Jenkins

After making commits to Bitbucket Server (previously known as Stash), notify Jenkins that a new build has been created.

Requirements

  • Git Plugin - Jenkins needs to have the Git Plugin installed in Jenkins and the Poll SCM option must be enabled

Setup

Once installed, follow these steps:

  • Navigate to a repository in Bitbucket Server.
  • Hit the Settings link
  • In the left-navigation, hit the Hooks link
  • For the Stash Webhook to Jenkins, click the Enable button.
  • Enter the URL to your Jenkins instance
  • Select the method that clone method that Jenkins is using (HTTP or SSH).
  • If using HTTP, enter the username that Jenkins is using to clone your repository.
  • Submit the form.
  • Commit some code and watch it trigger a build!

Troubleshooting

  • Check your log file for any exceptions
  • Be sure you have polling turned on for your project in Jenkins (just enable it... the schedule can be empty)
  • Verify that the URLs for your repository match in Jenkins and the webhook settings. They MUST be identical.
  • Still stuck? Check out the this wiki page or open an issue

Rate the Plugin

If you found this plugin useful, please consider leaving us a rating on our Atlassian Marketplace listing. Thanks!

Release Notes

Version 3.0.1

  • Fix to XSRF bug in Trigger Button (thanks JonMR for the PR)
  • Fix sha1 for test triggers and prevent sha1=null in URLs (thanks SuperTux88 for the PR)

Version 3.0.0

  • Updated support for Bitbucket Server (previously known as Stash)

Version 2.7.1

  • Fixed regression with branch parameter when using "Trigger Build" button on PR page
  • Add option to disable trigger button on PR page

Version 2.7.0

  • Restored pull-request notification
  • Make option to include/exclude branch information in Jenkins notification

Version 2.6.0

  • Added ability to not send commit hash in Jenkins notification
  • Reverted pull-request notifications back to where it was before

Version 2.5.1

  • Fixed a Javascript error when opening plugin settings
  • Added datacenter compatible flag

Version 2.5.0

  • Git Plugin version 2.0.2 or greater in Jenkins is highly recommended
  • No longer requires polling to be enabled for the git repository in Jenkins setup (REVERTED)
  • Added more metadata in webhook notification to Jenkins, including the sha1
  • Allows "Trigger Build" button to trigger a build multiple times

Special shoutout to loa for his pull request, work, and patience

Version 2.4.2

  • Fixed syntax error in Javascript for the "Trigger Build" button (thanks dojcsak for the pull request)

Version 2.4.1

  • Stash 3.0 support

Version 2.4.0

  • Added ability to whitelist or blacklist specific branches for triggering of Jenkins. (whitelist = branch HAS to be in list to trigger; blacklist = branch is IGNORED if in the list)

Version 2.3.1

  • Move Jenkins event notification off to its own thread pool to prevent Stash's event thread from blocking (thanks charleso for the pull request)
  • Fixed compatibility issue with versions of Stash before 2.8 (thanks xuey90 for the pull request)

Version 2.3.0

  • Created more helpful error messages during testing of the webhook on the configuration screen.

Version 2.2.2

  • Fixed NPE that occurs when event has a null user. Was seen using the SVN Mirror plugin.

Version 2.2.1

  • Fixed bug in which notifications no longer were sent when pull request is merged

Version 2.2

  • Added button to Pull Request page to trigger a build. Note that Jenkins will still only build if there is an actual change to build.

Version 2.1

  • Trigger webhooks when pull requests are opened, reopened, or updated (thanks stupchiy for the research and lordmatanza for the pull request)

Version 2.0.1

  • Fixed bug in which non-admin users were unable to access webhook settings

Version 2.0

  • Made setup of the Jenkins repository easier by adding SSH/HTTP quick select
  • Fire notification after pull-requests have been merged
  • Added a plugin logo
  • Added test button to the Hook Configuration display
  • Added ability to not send notifications if commits/merges are made by specified Stash users
  • Requires Stash 2.3.0
  • Renamed plugin to Stash Webhook for Jenkins

Version 1.1

  • Added an option to "Skip SSL Certificate Validation", allowing for plugin to communicate with Jenkins instance using a self-signed cert (setting is on Hooks settings for each project)
  • Handle Jenkins urls with trailing slashes more gracefully (thanks ellingbo)

Version 1

  • Initial release

stash-jenkins-postreceive-webhook's People

Contributors

alexbraidwood avatar ashnazg avatar atlasteve avatar bbaetz avatar brentm5 avatar ch3lo avatar cmclaughlin avatar cszmajda avatar ellingbo avatar faizhasim avatar hendrikhalkow avatar jonmr avatar jthomasatlassian avatar loa avatar mdavoodi avatar mikesir87 avatar ppodgorsek avatar stengerh avatar steveathon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stash-jenkins-postreceive-webhook's Issues

Multiple builds triggered

Stash is setup to send a notification to jenkins after a commit to the develop branch. However, after we merge a pull request, it will trigger two builds.

The first build (in hipchat) says something like "Started by changes from John Doe (x files(s) changed)

The second build will just say "Started by an SCM change"

The second build is triggered pretty soon after the first build (it doesn't run until the first build is finished, however).

image

The plugin could be made more generic

I installed this plugin and I am currently using it to notify my buildbot. Currently there is almost nothing Jenkins specific in this plugin and it could be used as a generic webhook.

One exception is that the plugins unconditionally adds the /git/notifyCommit?url=... part to the URL, but the whole generated URL could be put in the Jenkins URL field as well. It's a little less user friendly, but much more flexible.

Does this work for pull requests?

I saw the blog post about requiring build passes in order to merge a pull request, but I couldn't find any pull request hook plugins.

Does this run every time a new pull request is made?

If so, does it run again after the pull request is merged?

NullPointerException when pull request is created.

When I create a pull request, a NullPointerException is thrown.

I saw the other NPE issue, but my configuration has the 'Skip SSL Certification Validation' checkbox checked, so it may not be the same issue.

Based on the stack trace, this may be related to the 'Committers to ignore' option. This field is blank in my configuration.

Here is the error from the Stash log.

--snip--

2013-10-17 09:18:03,854 ERROR [AtlassianEvent::pool-3-thread-1] ---[identity removed=--- SSH - git-receive-pack '~dhanks/dhanks-cfmgt-filenameparsing.git' c.a.e.i.AsynchronousAbleEventDispatcher There was an exception thrown trying to dispatch event 'com.atlassian.stash.event.RepositoryPushEvent[source=com.atlassian.stash.internal.hook.PostReceiveEventHook@644d254e]' from the invoker 'SingleParameterMethodListenerInvoker{method=public void com.nerdwin15.stash.webhook.RepositoryChangeListener.onRefsChangedEvent(com.atlassian.stash.event.RepositoryRefsChangedEvent), listener=com.nerdwin15.stash.webhook.RepositoryChangeListener@5e123c18}'.
java.lang.RuntimeException: java.lang.NullPointerException
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:50) ~[atlassian-event-2.3.0.jar:na]
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:66) ~[atlassian-event-2.3.0.jar:na]
at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:38) ~[sal-core-2.10.3.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
Caused by: java.lang.NullPointerException: null
at com.nerdwin15.stash.webhook.service.eligibility.IgnoreCommittersEligibilityFilter.shouldDeliverNotification(IgnoreCommittersEligibilityFilter.java:41) ~[na:na]
at com.nerdwin15.stash.webhook.service.eligibility.ConcreteEligibilityFilterChain.shouldDeliverNotification(ConcreteEligibilityFilterChain.java:27) ~[na:na]
at com.nerdwin15.stash.webhook.RepositoryChangeListener.onRefsChangedEvent(RepositoryChangeListener.java:34) ~[na:na]
at sun.reflect.GeneratedMethodAccessor5099.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36) ~[atlassian-event-2.3.0.jar:na]
... 5 common frames omitted

---end snip---

Thanks,
Doug

Auto-Populate the Git Url

Why do I need to populate the URL of the Git repo i'm currently enabling a hook on? Surely the plugin is able to do this for me?

Can the UI have a dropdown: HTTP/SSH
Text Box: auto completes from selection above, but allows manual override

How to debug or get logs for the plugin?

Steps:

  1. Configured my jenkins job to enable Polling SCM with "H 0 1 1 0".
  2. Using 'curl', I can trigger my jenkins build: curl jenkins.xyz.com:8080/git/notifyCommit?url=ssh://[email protected]:7999/eee/repo.git

But, when I enable the plugin in Stash with Jenkins URL = jenkins.xyz.com:8080 and GIT repo URL = ssh://[email protected]:7999/eee/repo.git, merging my pull-request to the master branch does NOT trigger the jenkins build. Is there a way to look at logs for the plugin to figure out what's going on?

Can't enable plugin

Using Stash 2.5.0, installed the plugin freshly for the first time.

When I try to enable the plugin on an repository, I only get neverending spinning ball.

bildschirmfoto 2013-06-12 um 23 43 39

Parameterized build for different environment in Jenkins

Hi,

I have a requirement to do the build in different environment depends upon the parameter in Java application. Following are my environments

a) Development environment
b) Testing environment
c) Beta environment (would be production environment)

I have different parameters like connectivity, jdbc and ldap parameters for the above 3 environments that are maintained in resource bundle properties.
Currently, i am changing the parameters manually to deploy it respective environment.

If i have to do the build in Jenkins, i need to create three different jobs for 3 different environment

Requirement would be as follows:

a) On click of Development environment job, would pull the souce code from Git
b) Depends upon environment, it has to dynamically take the parameter from properties file and pass the
values to application.
c) Does the build and create a war file
d) Copy the war file in respective folders (Development artifact folder, test artifact folder and beta artifact
folder)

It would be appreciated to let me know what plugins / features exist in the Jenkins to take this forward or any work around solution.

Thanks,
Rhenatas

SSL Certificate Checks

Even with the checkbox checked to "Skip SSL Certificate Validation" I get the following error: Error: hostname in certificate didn't match: <sf-itjenkins-01> != <test site>

I am using the "default" SSL capability built into Jenkins, which apparently creates an SSL cert for "<test site>" (ugh)... I will look into that, but in the mean time, shouldn't "Skip SSL Certificate Validation" work?

Add the ability to test the hook

Please consider adding a button in the settings dialog to trigger test builds against Jenkins. I think that would be better than having users do test commits and pushing to ensure they have the correct URLs.

Have Jenkins build pull request merge products

Identify the SHA of the current head of a pull request merge product (refs/pull-requests/*/merge) and use that to trigger a build of the merge product in Jenkins.

Note that this might break reporting by the Jenkins StashNotifier plugin as that relies on the SHA to report, I imagine the reporting itself will happen correctly but the merge product SHA is not one of the commits listed in the Stash pull request UI. It would be an acceptable hack if we could somehow send the source branch SHA as a parameter and use that for reporting build results back to Stash.

Enable "Trigger Build" button to rerun a build

Currently the "trigger build" button triggers Jenkins to poll Stash, if a build has already completed for a given commit Jenkins will not rerun that build.

The Jenkins Git plugin API can take a SHA as a parameter. Would it be possible to have the plugin calculate the most recent SHA in a pull request and have Jenkins rebuild that commit when the "trigger build" button is pressed?

Would it also be possible to provide a configuration option so that rather than sending the SHA of the source branch the plugin sent the SHA of the merge product of the source and target created by Stash (refs/pull-requests/*/merge)?

I can provide use cases and details if that would be helpful.

Thanks,
Jim

blacklist feature not working?

We have configured 'Ignore from' option of this hook with value of 'master production release/* integration/* sandbox/* ' , but all of these branches are still being built for every new change detected in git repository. Tried look into the source code, but still clueless. Does it work for anyone?

Ignore commits by Jenkins

Would be great if could have a way to ignore comments by git email address instead of something specific to Stash.

For Jenkins, I've just an access key directly to the repository, but since that user doesn't have a Stash account, it seems I can't block commits from Jenkins. This is causing a loop in my build server as I do a commit during build to update version numbers automatically.

Either somewhat to ignore commits by access key as well, or maybe the ability to ignore commits where the comment matches a particular regex. I would like to ignore commits which have a comment similar to something like 'Release x.x.x'.\

Maybe others have been able to do this another way, or I'm missing something.

Thanks
Steph

Jenkins webhook trigger failing due to permissions?

For control reasons, I have my repository in Stash locked down so that no 'real' user has write access. Developers can review and approve pull requests, but not merge. I am using the Workzone Stash plugin to perform automatic merges once sufficient approvals of a pull request are received. The automatic merge is configured to use a special 'non-interactive' account that does have write access to the repository.

When the pull request is approved and merged, it looks like the Stash Jenkins Webhook is failing due to a permissions error. It looks like it is using the effective permission of the user logged in when the automatic merge occurs.

Below are partial snippets of the 2 errors I found in the Stash log file that lead me down this path. These are the only log entries that would indicate why my jenkins jobs are not getting triggered.

If this is the case, is there a way to have Stash run this EventListener as a different user?

---snip---

2013-10-16 11:48:36,428 ERROR [AtlassianEvent::pool-3-thread-2] ---[identifying information removed]--- "POST /rest/api/latest/projects/CFMGT/repos/cfmgt/pull-requests/2/approve HTTP/1.1" c.a.e.i.AsynchronousAbleEventDispatcher There was an exception thrown trying to dispatch event 'com.atlassian.stash.repository.sync.RefsSynchronizedEvent[source=com.atlassian.stash.internal.repository.sync.DefaultRefSyncService@302b25c0]' from the invoker 'SingleParameterMethodListenerInvoker{method=public void com.nerdwin15.stash.webhook.RepositoryChangeListener.onRefsChangedEvent(com.atlassian.stash.event.RepositoryRefsChangedEvent), listener=com.nerdwin15.stash.webhook.RepositoryChangeListener@5e123c18}'.
java.lang.RuntimeException: You are not permitted to access this resource
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54) ~[atlassian-event-2.3.0.jar:na]
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:66) ~[atlassian-event-2.3.0.jar:na]
at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:38) ~[sal-core-2.10.3.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
Caused by: com.atlassian.stash.exception.AuthorisationException: You are not permitted to access this resource
at com.atlassian.stash.internal.aop.ExceptionRewriteAdvice.afterThrowing(ExceptionRewriteAdvice.java:36) ~[stash-platform-2.6.2.jar:na]
at sun.reflect.GeneratedMethodAccessor1802.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invokeHandlerMethod(ThrowsAdviceInterceptor.java:144) ~[spring-aop-3.2.3.RELEASE.jar:3.2.3.RELEASE]

---end snip---

---snip---

2013-10-16 11:48:36,640 ERROR [AtlassianEvent::pool-3-thread-2] ---[identifying information removed]--- "POST /rest/api/latest/projects/CFMGT/repos/cfmgt/pull-requests/2/approve HTTP/1.1" c.a.e.i.AsynchronousAbleEventDispatcher There was an exception thrown trying to dispatch event 'com.atlassian.stash.repository.sync.RefsSynchronizedEvent[source=com.atlassian.stash.internal.repository.sync.DefaultRefSyncService@302b25c0]' from the invoker 'SingleParameterMethodListenerInvoker{method=public void com.wittified.TaskRepositoryEvent.postReceive(com.atlassian.stash.event.RepositoryRefsChangedEvent), listener=com.wittified.TaskRepositoryEvent@8efa324}'.
java.lang.RuntimeException: An error occurred while executing an external process: [e02b6a2]: Unexpected output; expected a 'commit' object
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54) ~[atlassian-event-2.3.0.jar:na]
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:66) ~[atlassian-event-2.3.0.jar:na]
at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:38) ~[sal-core-2.10.3.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
Caused by: com.atlassian.stash.exception.ServerException: An error occurred while executing an external process: [e02b6a2]: Unexpected output; expected a 'commit' object
at com.atlassian.stash.internal.scm.git.GitCommandExitHandler.evaluateThrowable(GitCommandExitHandler.java:120) ~[na:na]
at com.atlassian.stash.internal.scm.git.GitCommandExitHandler.onCancel(GitCommandExitHandler.java:46) ~[na:na]
at com.atlassian.stash.scm.BaseCommand.callExitHandler(BaseCommand.java:138) ~[stash-spi-2.6.2.jar:na]
at com.atlassian.stash.scm.BaseCommand$CommandFuture.internalGet(BaseCommand.java:257) ~[stash-spi-2.6.2.jar:na]
at com.atlassian.stash.scm.BaseCommand$CommandFuture.get(BaseCommand.java:224) ~[stash-spi-2.6.2.jar:na]

---end snip---

Thanks,
Doug Hanks

Any chance to support Stash 2.6.3?

Is it possible to support stash 2.6.x with this plugin? I tried updating the version and building locally, but doesn't build (even when its 2.2.0)

Manual trigger button

There are circumstances where it's very handy to have a manual Jenkins trigger button available.

I'll explain a situation that we've come across.
When you create a pull-request from branch X to branch Y, the latest version of the plugin triggers a build on Jenkins, all is well.
However, when another developer would then commit something to branch Y, the build of the pull-request is out of date, since the target branch was modified.
When you would then open the pull-request in the Stash pages, a new automerge is created in the background.
At this moment no build is triggered since every open pull-request with target branch Y would have to be triggered.
This would stress the Jenkins buildserver too much.

In our Stash setup we use the stash-jenkins-postreceive-webhook plugin combined with the stash-build-status-plugin.
The latter one disables the Stash merge-button until a successful build of the automerge was performed.
This will however also block the pull-request from being merged when branch Y was updated in the meanwhile.

A button to trigger a build manually would circumvent this problem.

Bug in using SSH

On the current develop branch, the repo URL is generated and can be overridden with a new base URL. The URL is generated using the NavBuilder. Apparently, the URL provided does not work for SSH, even if swapping out the base URL.

Example:
HTTP Clone URL: http://test.jenkins/stash/scm/test/helloworld.git
SSH Clone URL: ssh://[email protected]:7999/test/helloworld.git
NavBuilder Provides: http://test.jenkins/stash/scm/test/helloworld.git

Note that there's the extra /scm/ in the HTTP/NavBuilder URL. The fix is simply to replace the /scm/ if a Overridden Base URL uses SSH. But, want a second pair of eyes to confirm.

Webhook trigering multiple builds

Hi,

we're making heavy use of your webhook and firstly I'd like to say how fantastic it is!

We have one slight issue - we have multiple jenkins jobs pointing at the same Stash repo, each job configured to build a different branch.

What I'm seeing is, when I push to one branch, the build for that branch is triggered, but also builds for other branches too.

Could this be a problem in the way I've set things up? Am I misunderstanding something? Or could it be a bug in the webhook?

Many thanks

Strange exception for non-admin users

Hi!

We get a strange exception for non-admin users that only have write permission to the repo:

    at sun.proxy.$Proxy223.getSettings(Unknown Source) ~[na:na]
    at com.nerdwin15.stash.webhook.service.eligibility.IgnoreCommittersEligibilityFilter.shouldDeliverNotification(IgnoreCommittersEligibilityFilter.java:39) ~[na:na]
    at com.nerdwin15.stash.webhook.service.eligibility.ConcreteEligibilityFilterChain.shouldDeliverNotification(ConcreteEligibilityFilterChain.java:27) ~[na:na]
    at com.nerdwin15.stash.webhook.RepositoryChangeListener.onRefsChangedEvent(RepositoryChangeListener.java:34) ~[na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_24]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.6.0_24]

The hook ends up with

java.lang.RuntimeException: You are not permitted to access this resource

in atlassian-stash.log.

For admin users everything works fine. For all others the hook is not completed.

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

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.

For a single job, multiple builds are sometimes triggered for a single commit

On an intermittent basis, a single job will be started twice for a single change. When I push a commit to Stash, sometimes the same Jenkins job (for that development branch or maybe a job that runs off the master when merging to the master) will be started twice.

I do have "Execute concurrent builds if necessary" enabled for the job in Jenkins as I do want to have multiple builds running if there is a newer commit pushed while the existing build is still running.

2.5 Triggers every build on commit

When we upgraded the plugin to 2.5, every commit on Stash causes Jenkins all builds to start. We did not see this happen with version 2.4, only on the upgrade. This is a big problem as it was causing even builds that should not be triggered by a commit to start.

Any idea what could be causing this?

Ability to notify multiple Jenkins servers

We have multiple Jenkins servers building different platforms. At the moment each commit can only notify a single Jenkins environment, but being able to notify more than one would be extremely useful.

In my case, just the ability to add multiple URLs would be fine as the remaining properties are the same in each instance.

Plugin admin settings breaks on Stash 3.2.0

When trying to configure the plugin - I'm receiving this error (when trying to configure the settings for the hook (in settings in the repo) -

Failed to load config form: com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook-config-form, errors: TypeError: Cannot read property 'nerdwin15' of undefined

It also seems that since upgrading from 3.1.x to 3.2.0 - the plugin is no longer triggering our Jenkins server

We are using the latest version of the plugin 2.5.0

Doesn't appear in UPM view

Right now the plugin doesn't appear in the in-product marketplace view (the Universal Plugin Manager) for Stash 2.4.1.
I suspect that is because of the claimed version compatibility. I don't know if there is an easy way to mark your plugin as 'forward-compatible' from 2.2.0 - 2.X or whatever, or if you have to update it with each release of Stash.

RepositoryChangeListener should not block the event thread(s) while sending notifications to Jenkins

RepositoryChangeListener sends a notification to Jenkins on the event thread. This is a remote call that can block the event thread if the network is slow or the Jenkins server is slow to respond. If the Jenkins instance is structurally slow, all event threads will eventually get blocked trying to send notifications to Jenkins and event processing will fail.

Ideally, the notification to Jenkins should use an asynchronous HTTP request and not block the threads. See https://hc.apache.org/httpcomponents-asyncclient-dev/httpasyncclient/examples/org/apache/http/examples/nio/client/AsyncClientHttpExchangeFutureCallback.java for an example.

Michael Heemskerk
Atlassian Stash

Updated pull requests do not trigger a build on Jenkins.

Hi,

We recently upgraded from Stash 2.5.4 to 3.2.0 and in doing so moved to the 2.5.0 version of the Stash Jenkins Webhook. We noticed that the plugin will trigger builds on an initial pull request. However, if the pull request is subsequently updated with an additional commit no additional build is triggered. This wasn't the case in the previous version of the plugin.

I noticed you had a 2.5.1-SNAPSHOT version for another issue and I am wondering if that same JavaScript issue was affecting us in this case as well.

Thanks for this plugin by the way.

Trigger build on new push to pull requests

(copying comments from blog)

-- Comment from 12/4 11:10

We tried to use your plugin with Stash Pull Requests, but encountered a problem, I know that it is on Stash side, but want to ask if you have some workaround in mind:

What we want to accomplish is:

  1. Open Pull Request in Stash for specific
  2. After Pull Request is openned trigger "Pull Request Build Job" in Jenkins
    (we are using Git Plugin in Jenkins and specifying refspec
    parameters: "+refs/pull-requests/:refs/remotes/origin/pull-requests/"
    and building the "origin/pull-requests/*/from" branch)
    Jenkins WebHook plugin is setup to trigger job by commit to Stash Repo
  3. Initiate Review process with changes discussion
  4. Do commit changes and update pull-request with new commits due to discussion
    (Here we get trouble, cause your plugin is sending trigger after commit, but poll scm from Jenkins can't find nothing, cause stash updates the reference - "refs/pull-requests/*/from" only if it was Approved in Pull Request)
  5. We want to Trigger Jenkins build for new commits in the "Pull Request Build Job"
  6. Review again, approve, merge

But to update reference and have additional commits in the same Pull we need to Approve and Unapprove each time after commit, which is makes no sense

Do you have any workaround or any ideas how to adopt this to Pull Requests process?

------ Comment on 12/4 11:57

I got a fast reply from Atlassian Developer according to this.
Michael could be interesting for you as a feature, since he also submitted some code snippet how to solve this - https://answers.atlassian.com/questions/239988/change-pull-request-refs-after-commit-instead-of-after-approval-or-workaround

Notify isn't triggered (in branch)

Hello,

I have installed yesterday your hook, which looks very good (great work!), but it seems that no notify is triggered after a commit into a branch. I am using Stash 2.8.4.
In the configuration of the hook all work fine and it is possible to trigger a polling.

I have enabled debug output for the Notifier and JenkinsResource class, but I get no output when committing something.
It makes no difference using an administrative account or a normal user. It seems like the Notifier class isn't called at all.
No exceptions or similar can be found. I don't know how to activate the debug log for the Hook Service otherwise I had looked into its log.

What could be wrong?

Error message "An error occurred"

Hi,

I'm using the Stash Webhook to Jenkins plugin v.2.4.1 with Stash v.2.12.1 and the following message shows up each time I click on the "Enable" button for the plugin in the Hooks Settings page for any repo :

"An error occured" "Something went wrong while trying to serve your request. Try reloading the page."

image

If I click "Reload the page", the config. window closes and nothing happens.

If I click "Close" instead of "Reload" I can then fill all the required fields and press "Enable". If I come back and edit the configuration, I will see the error message again.

The plugin works correctly except for the error message that is displayed without reason.

Could you fix it or tell me if there is a workaround?

Thanks.

AccessDeniedException on commit of non-admin user

I am getting this when a non admin user commits to the branch, no build is scheduled in jenkins. Admin users can commit and trigger the build.

c.a.s.i.e.AsyncBatchingInvokersTransformer There was an exception thrown trying to dispatch event 'com.atlassian.stash.event.RepositoryPushEvent[source=com.atlassian.stash.internal.hook.PostReceiveEventHook@3cecd9df]' for the invoker 'SingleParameterMethodListenerInvoker{method=public void com.nerdwin15.stash.webhook.RepositoryChangeListener.onRefsChangedEvent(com.atlassian.stash.event.RepositoryRefsChangedEvent), listener=com.nerdwin15.stash.webhook.RepositoryChangeListener@443ca59a}'.
java.lang.RuntimeException: You are not permitted to access this resource
        at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54) ~[atlassian-event-2.3.0.jar:na]
        at com.atlassian.stash.internal.event.AsyncBatchingInvokersTransformer$AsyncInvokerBatch.invoke(AsyncBatchingInvokersTransformer.java:100) ~[stash-platform-2.9.4.jar:na]
        at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:66) [atlassian-event-2.3.0.jar:na]
        at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:38) [sal-core-2.10.9.jar:na]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_45]
        at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
        ... 1 frame trimmed
Caused by: com.atlassian.stash.exception.AuthorisationException: You are not permitted to access this resource
        at com.atlassian.stash.internal.aop.ExceptionRewriteAdvice.afterThrowing(ExceptionRewriteAdvice.java:36) ~[stash-platform-2.9.4.jar:na]
        at com.sun.proxy.$Proxy194.getSettings(Unknown Source) ~[na:na]
        at com.sun.proxy.$Proxy230.getSettings(Unknown Source) ~[na:na]
        at com.sun.proxy.$Proxy230.getSettings(Unknown Source) ~[na:na]
        at com.nerdwin15.stash.webhook.service.eligibility.IgnoreCommittersEligibilityFilter.shouldDeliverNotification(IgnoreCommittersEligibilityFilter.java:39) ~[na:na]
        at com.nerdwin15.stash.webhook.service.eligibility.ConcreteEligibilityFilterChain.shouldDeliverNotification(ConcreteEligibilityFilterChain.java:27) ~[na:na]
        at com.nerdwin15.stash.webhook.RepositoryChangeListener.onRefsChangedEvent(RepositoryChangeListener.java:34) ~[na:na]
        at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36) ~[atlassian-event-2.3.0.jar:na]
        ... 6 common frames omitted
Caused by: org.springframework.security.access.AccessDeniedException: Access is denied
        at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:83) ~[spring-security-core-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        ... 13 common frames omitted

Build Success does not clear the overall Build Failure status

When viewing the Build Status for a given PR overall, as well as for individual commits, a single Build Failure will result in the overall Build Status to be shown as Failure even when subsequent builds are successful.

Note how the overall PR build status shows failure (far right), but the popup build history shows the most recent build was successful:
bug-overallbuild

Here again, note how the given commit (the top one) shows build failure (far right), but the popup build history for it shows the most recent build was successful:
bug-commitbuild

I wanted to check with you, the plugin, to see what you think about there the icon choice bug might be, before filing a bug with Stash itself.

Plugin disabled in all repos after update

I've been using this plugin for about a week, it works really well, but this morning I installed an update when Stash notified me a new version was available. I've just realised that as a result the plugin is no longer enabled in any of my repositories.

This is really annoying, will this happen every time it updates? That seems untenable.

I'm not really sure what version I was running before but I can hunt through the backups if you need that info.

NPE at hook

We get code via Subversion Mirror into stash.
But the hook to jenkins never get fired. Manually Testing works fine.

Logfile:
2014-01-22 00:34:47,776 ERROR [AtlassianEvent::pool-2-thread-6] c.a.s.i.e.AsyncBatchingInvokersTransformer There was an exception thrown trying to dispatch event 'com.atlassian.stash.event.RepositoryPushEvent[source=org.tmatesoft.subgit.stash.web.SgRepositoryManager@41219615]' for the invoker 'SingleParameterMethodListenerInvoker{method=public void com.nerdwin15.stash.webhook.RepositoryChangeListener.onRefsChangedEvent(com.atlassian.stash.event.RepositoryRefsChangedEvent), listener=com.nerdwin15.stash.webhook.RepositoryChangeListener@13e1c6a6}'.
java.lang.RuntimeException: java.lang.NullPointerException
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:50) ~[atlassian-event-2.3.1.jar:na]
at com.atlassian.stash.internal.event.AsyncBatchingInvokersTransformer$AsyncInvokerBatch.invoke(AsyncBatchingInvokersTransformer.java:100) ~[stash-platform-2.10.0.jar:na]
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2$1.run(AsynchronousAbleEventDispatcher.java:52) [atlassian-event-2.3.1.jar:na]
at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:38) [sal-core-2.10.9.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_51]
... 1 frame trimmed
Caused by: java.lang.NullPointerException: null
at com.nerdwin15.stash.webhook.RepositoryChangeListener.onRefsChangedEvent(RepositoryChangeListener.java:47) ~[na:na]
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36) ~[atlassian-event-2.3.1.jar:na]
... 6 common frames omitted

May anyone can help me or fix it if it is an bug.

Thank you,
Thomas

Branch names with slashes not building

Hello,
I've been trying to test the plugin but am unable to trigger a build for branches with a slash. For example, a branch name of "users/johny" won't build, but the "master" branch will.

NullPointerException when 'Skip SSL Certificate Validation' unchecked

We use HTTPS exclusively for Jenkins, and it is a genuine, non-self-signed certificate, so I didn't check 'Skip... Validation' at first. However, this didn't work, and I had to turn on Stash debugging to find out why. This was in catalina.out:

java.lang.NullPointerException
        at com.nerdwin15.stash.webhook.service.ConcreteHttpClientFactory.getHttpClient(ConcreteHttpClientFactory.java:36)
        at com.nerdwin15.stash.webhook.JenkinsWebhook.postReceive(JenkinsWebhook.java:47)
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAdapter.java:49)
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAdapter.java:44)
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$8.doInTransaction(DefaultRepositoryHookService.java:412)
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$8.doInTransaction(DefaultRepositoryHookService.java:406)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService.visitEnabledHooks(DefaultRepositoryHookService.java:406)
        at sun.reflect.GeneratedMethodAccessor574.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
        at com.atlassian.stash.internal.aop.ProfilingAspect.profileMethod(ProfilingAspect.java:43)
        at sun.reflect.GeneratedMethodAccessor149.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
        at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:64)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:124)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at com.sun.proxy.$Proxy182.visitEnabledHooks(Unknown Source)
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.postReceive(AsyncPostReceiveRepositoryHookAdapter.java:44)
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.onRefsChangedEvent(AsyncPostReceiveRepositoryHookAdapter.java:39)
        at sun.reflect.GeneratedMethodAccessor769.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36)
        at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:66)
        at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:38)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

It does work now that I have the box checked, which is an acceptable workaround. Just letting you know. Thanks for sharing this webhook!

Better error message when trigger build fails

When you press the "Trigger Jenkins" button and something goes wrong, it displays "It didn't work!" Would it be possible to display a more helpful error message that would indicate what didn't work?

Trigger seems to be not working - how to debug

Hi!

I set up a post receive hook in order to trigger a Jenkins build as soon as there is a change committed to branch develop. Rationale: we do not want to wait until Jenkins would poll for changes but to proactively start a new build the moment some change was committed.

In Stash, I configured Stash Post-Receive Webhook to Jenkins with the following values:

  • Jenkins URL: https://jenkins.local/job/product-develop/build?token=foobar&cause=Triggered%20by%20Stash%20Post-Receive%20Webhook
  • Git Repo URL: ssh://[email protected]:7999/PROD/code.git
  • Skip SSL Certificate Validation: checked

In Jenkins, I am using the following configuration (among other settings, obviously):

  • Git / Repository URL: ssh://[email protected]:7999/PROD/code.git
  • Git / Branches to build: origin/develop
  • Trigger builds remotely (e.g., from scripts): checked
  • Authentication Token: foobar
  • Poll SCM: checked
  • Schedule: "every five minutes"

However, it seems that Stash Post-Receive Webhook never connects to Jenkins. At least, no new build gets scheduled.

Why is it required to enable the "Poll SCM option" anyway? I actually want to trigger builds remotely via the Stash Post-Receive Webhook and not via Jenkin's polling mechanism. I think there is a misunderstanding on my part, right?

Regards,

Martin

Example for hard coded urls?

Hi, i tried myself but i could not figure it out.

Could you add an example where the user can only select from say 3 different jenkins urls?

From what i can gather, i would think i only need to have a change to the simply.soy no?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.