Coder Social home page Coder Social logo

nemccarthy / stash-pullrequest-builder-plugin Goto Github PK

View Code? Open in Web Editor NEW
64.0 10.0 132.0 239 KB

A Jenkins plugin for Building Stash Pull Requests

Home Page: https://wiki.jenkins-ci.org/display/JENKINS/Stash+pullrequest+builder+plugin

License: Other

Java 99.59% HTML 0.41%

stash-pullrequest-builder-plugin's Introduction

Stash Pull Request Builder Plugin

This plugin is now maintained in the offical Jenkins org; https://github.com/jenkinsci/stash-pullrequest-builder-plugin Please direct all PRs there.

Join the chat at https://gitter.im/nemccarthy/stash-pullrequest-builder-plugin

This Jenkins plugin builds pull requests from a Atlassian Stash server and will report the test results as a comment. This plugin was inspired by the GitHub & BitBucket pull request builder plugins.

Prerequisites

Parameter variables

The plugin makes available to the job the following parameter variables:

  • ${pullRequestId}
  • ${pullRequestTitle}
  • ${sourceBranch}
  • ${targetBranch}
  • ${sourceRepositoryOwner}
  • ${sourceRepositoryName}
  • ${destinationRepositoryOwner}
  • ${destinationRepositoryName}
  • ${sourceCommitHash}
  • ${destinationCommitHash}

Creating a Job

Source Code Management

Select Git then configure:

  • Repository URL: [email protected]:/${destinationRepositoryOwner}/${destinationRepositoryName}.git
  • Advance -> Refspec: +refs/pull-requests/*:refs/remotes/origin/pr/*
  • Branch Specifier: origin/pr/${pullRequestId}/from

Build Triggers

Select Stash Pull Request Builder then configure:

  • Cron: must be specified. eg: every 2 minute H/2 * * * *
  • Stash Host: the http or https URL of the Stash host (NOT ssh). eg: https://example.com
  • Stash Credentials: Select or Add the login username/password for the Stash Host
  • Project: abbreviated project code. eg: PRJ or ~user
  • RepositoryName: eg: Repo

Advanced options

  • Ignore ssl certificates:
  • Build PR targetting only these branches: common separated list of branch names (or regexes). Blank for all.
  • Rebuild if destination branch changes:
  • Build only if Stash reports no conflicts: this should be set if using the merge branch to avoid issues with out of data merge branch in stash
  • Build only if PR is mergeable (note this will stop the PR being built if you have required approvers limit set >0 and the PR hasn't been approved)
  • Cancel outdated jobs
  • CI Skip Phrases: default: "NO TEST"
  • Only build when asked (with test phrase):
  • CI Build Phrases: default: "test this please"
  • Target branches: a comma separated list of branches (e.g. brancha,branchb)

Building the merge of Source Branch into Target Branch

You may want Jenkins to build the merged PR (that is the merge of sourceBranch into targetBranch) to catch any issues resulting from this. To do this change the Branch Specifier from origin/pr/${pullRequestId}/from to origin/pr/${pullRequestId}/merge

If you are building the merged PR you probably want Jenkins to do a new build when the target branch changes. There is an advanced option in the build trigger, "Rebuild if destination branch changes?" which enables this.

You probably also only want to build if the PR was mergeable and always without conflicts. There are advanced options in the build trigger for both of these.

NOTE: Always enable Build only if Stash reports no conflicts if using the merge RefSpec! This will make sure the lazy merge on stash has happened before the build is triggered.

Merging Locally

If you dont want to use the lazy merged Stash PR RefSpec (described above) the other option is to do the merge locally as part of the build using the Jenkins git plugin (these only work for branches within the same repo);

  1. Select Git SCM
  2. Add Repository URL as bellow [email protected]:${projectCode}/${repositoryName}.git
  3. In Branch Specifier, type as bellow */${sourceBranch}
  4. In the "Source Code Management" > "Git" > "Additional Behaviors" section, click "Add" > "Merge Before Building"
  5. In "Name of Repository" put "origin" (or, if not using default name, use your remote repository's name. Note: unlike in the main part of the Git Repository config, you cannot leave this item blank for "default".)
  6. In "Branch to merge to" put ${targetBranch}
  • Note that as long as you don't push these changes to your remote repository, the merge only happens in your local repository.

Alternatively if you want to use Stash's origin/pr/${pullRequestId}/from branch specifier and merge locally to avoid the race condition without checking stash if the PR is conflicted using the merge branch spec then;

  1. Use the origin/pr/${pullRequestId}/from branch specifier
  2. In the "Source Code Management" > "Git" > "Additional Behaviors" section, click "Add" > "Merge Before Building"
  3. Set the "Branch to merge to" to ${targetBranch}
  4. Alternatively to the above 3 steps, just run a git merge $destinationCommitHash

If you have downstream jobs that are not triggered by this plugin you can simply add a if condition on this command to check if the parameters are available;

if [ ! -z "$destinationCommitHash" ]; then
    git merge $destinationCommitHash
fi

Notify Stash of build result

If you are using the StashNotifier plugin and have enabled the 'Notify Stash Instance' Post-build Action while building the merged PR, you need to set ${sourceCommitHash} as Commit SHA-1 to record the build result against the source commit.

Rerun test builds

If you want to rerun pull request test, write "test this please" comment to your pull request.

##Adding additional parameters to a build

If you want to add additional parameters to the triggered build, add comments using the pattern p:<parameter_name>=<value>, one at each line, prefixed with p:. If the same parameter name appears multiple times the latest comment with that parameter will decide the value.

Example:

test this please
p:country=USA
p:env=dev1

Post Build Comment

It is possible to add a post build action that gives the option to post additional information to Stash when a build has been either successful or failed. These comments can contain environment variables that will be translated when posted to Stash.

This feature can be used to post for instance a url to the deployed application or code coverage at a successful build and why the build failed like what tests that did not pass.

License

  • BSD License

Copyright (c) 2015, Nathan McCarthy All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Nathan McCarthy BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

stash-pullrequest-builder-plugin's People

Contributors

danengelbrecht avatar dieu avatar dlmr avatar eirikwang avatar gitter-badger avatar jsmigel avatar jwstric2 avatar kutsal avatar laurent-verbruggen-at-kbc avatar loicalbertin avatar lwalkera avatar mandrizzle avatar nemccarthy avatar nickbroon avatar olgamaciaszek avatar pierrebtz avatar rhencke avatar soasme avatar stephenc avatar superdave 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stash-pullrequest-builder-plugin's Issues

Wishlist: Add environment variables to Jobs

The GitHub pull-request plugin adds some useful Environment variables to the job, which enables some interesting tests to be performed. In our example, we would like to run static analysis on just the touched file of the commit, ensuring gradual improvement of code-quality. (Large code-base)

For that, we need something akin to "ghprbTargetBranch", to figure out which files is changed by this PR.

Could this be implemented?

Jenkins build server is offline, but STASH pull request is still triggering a build

We have this plugin configured for multiple build jobs that associated with three different jenkins build servers. One of these build servers has been turned off. Every time we type in 'please test this' in a particular repository associated to said offline server, the comment section of the Pull Request notes that the pull request build job started and then shows failed, increments the number, but the link is broken because the server is shutdown.

We are completely at a loss on what is happening. How or where do we find where this build job is being triggered because it can't be happening on the server that is offline.

Thanks much!

Couldn't find any revision to build When sourceBranch does not exist upstream

When I send a pull request from my fork f, branch b1, to the origin repo o branch master, the pull request fails (i think) as b1 does not exist in o.

[EnvInject] - Loading node environment variables.
Building in workspace /Users/server/.jenkins/jobs/PR Builder/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url ssh://git@... # timeout=10
Fetching upstream changes from ssh://git@...
 > git --version # timeout=10
using GIT_SSH to set credentials ci-user ssh key
 > git -c core.askpass=true fetch --tags --progress ssh://git@... +refs/pull-requests/*:refs/remotes/origin/pr/*
 > git rev-parse refs/remotes/origin/b1^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/b1^{commit} # timeout=10
 > git rev-parse origin/b1^{commit} # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Notified Stash for commit with id d31ee53bc4cc0dc74aa01e2932d1533d64958947
Finished: FAILURE

[TEST] Test task is failing

@nemccarthy thank you for this awesome plugin. I just forked this repo and was running the test task and I have 2 failing tests for the 8 tests in the project. I have did a fresh pull and I am running Maven 3.3.1 and Java 1.8.0_25. Can you confirm that the tests are failing for you as well?

Not kicking off builds appropriately, logs unclear

Working on prototyping this plugin, but it's not working. (I'm using the latest release from Jenkins Central).

Checking the logs, I see this the below error.

I'm entirely unclear (from the logs) what exactly is going wrong (which would allow me to quickly diagnose it)

Instead, I am now going to go over to the code and read it. :-(

May 06, 2015 5:16:01 PM WARNING stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient getPullRequests
invalid pull request response.
java.lang.NullPointerException
    at java.io.StringReader.<init>(StringReader.java:50)
    at org.codehaus.jackson.JsonFactory.createJsonParser(JsonFactory.java:636)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient.parsePullRequestJson(StashApiClient.java:190)
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient.getPullRequests(StashApiClient.java:46)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashRepository.getTargetPullRequests(StashRepository.java:55)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashPullRequestsBuilder.run(StashPullRequestsBuilder.java:30)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger.run(StashBuildTrigger.java:152)
    at hudson.triggers.Trigger.checkTriggers(Trigger.java:266)
    at hudson.triggers.Trigger$Cron.doRun(Trigger.java:214)
    at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:54)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

May 06, 2015 5:20:01 PM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger run
Build Skip.
May 06, 2015 5:21:01 PM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashPullRequestsBuilder run
Build Start.
May 06, 2015 5:21:01 PM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashRepository getTargetPullRequests
Fetch PullRequests.
May 06, 2015 5:21:01 PM WARNING stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient getPullRequests
invalid pull request response.
java.lang.NullPointerException
    at java.io.StringReader.<init>(StringReader.java:50)
    at org.codehaus.jackson.JsonFactory.createJsonParser(JsonFactory.java:636)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient.parsePullRequestJson(StashApiClient.java:190)
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient.getPullRequests(StashApiClient.java:46)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashRepository.getTargetPullRequests(StashRepository.java:55)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashPullRequestsBuilder.run(StashPullRequestsBuilder.java:30)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger.run(StashBuildTrigger.java:152)
    at hudson.triggers.Trigger.checkTriggers(Trigger.java:266)
    at hudson.triggers.Trigger$Cron.doRun(Trigger.java:214)
    at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:54)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Comment log checker does not handle build names with regex characters

The regular expressions created for looking for build started and build finished message in the comments is inserting the build job name directly as part of the regular expression. That works if the build job name is a simple name, but in our case we had some text in parentheses in the name of the build job. The regex parser took that as a capture group so the match failed because it would not match the parentheses in the name.

You should use a capture group for the job name and then compare the captured text to the build job name or else use java.util.regex.Pattern.quote to add any necessary escape characters. Here is a patch that fixes it:

diff --git a/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java b/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
index 2d9bf76..efca26d 100644
--- a/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
+++ b/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
@@ -157,8 +157,9 @@ public class StashRepository {
                     }

                     //These will match any start or finish message -- need to check commits
-                    String project_build_start = String.format(BUILD_START_REGEX, builder.getProject().getDisplayName());
-                    String project_build_finished = String.format(BUILD_FINISH_REGEX, builder.getProject().getDisplayName());
+                    String escapedBuildName = Pattern.quote(builder.getProject().getDisplayName());
+                    String project_build_start = String.format(BUILD_START_REGEX, escapedBuildName);
+                    String project_build_finished = String.format(BUILD_FINISH_REGEX, escapedBuildName);
                     Matcher startMatcher = Pattern.compile(project_build_start, Pattern.CASE_INSENSITIVE).matcher(content);
                     Matcher finishMatcher = Pattern.compile(project_build_finished, Pattern.CASE_INSENSITIVE).matcher(content);

Builds won't start if branch has restricted permissions

If branch permissions are added in stash for a branch and the user jenkins uses is not listed as a user the pull-request won't start. This is strange since the access permissions only prevents writing to the branch and just fetch/checkout/merge locally on the build machine should not be blocked by that.

If I add the jenkins stash user to the list of users for the permission the build starts as expected.

Support Pipeline plugin from Jenkins 2.0

Would allow using this plugin programatically from a Jenkinsfile

Details at:
https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md#plugin-developer-guide

Possibly as simple as replacing AbstractBuild with Run

stashnotifier-plugin is looking to implement similar support: jenkinsci/stashnotifier-plugin#92

There is already a plugin that supports both BitBucket Cloud and Bitbucket Server/Stash along similar lines, though it's support for PR's is more limited, not supporting things like using the merge branch, etc and is restricted to multi-branch source type Jobs. https://github.com/jenkinsci/bitbucket-branch-source-plugin https://documentation.cloudbees.com/docs/cje-user-guide/bitbucket.html

It appears that @tjkierzkowski may have made a start on this:https://github.com/nemccarthy/stash-pullrequest-builder-plugin/compare/master...tjkierzkowski:pipeline_conversion?expand=1

Feature Request: Certificate based authentication

Hello. Thanks for this plugin. It seems very promising for us. We can't use it as-is though due to basic authentication.

Any chance you guys can implement certificate based authentication for us folks who don't have basic auth as a connectivity option?

Thanks in advance

Parameterize build

I created a Stash plugin that can trigger this plugin, so that polling can be avoided:
https://github.com/tomasbjerre/pull-request-notifier-for-stash
It has an admin GUI where checkboxes for different events can be enabled. And a custom URL, supporting variables, is added. Then when any of the events are triggered, the URL is rendered and invoked.

For example when a pull request is OPENED, or REOPENED, the plugin can invoke a URL that includes, from repo, from hash, to repo and to hash.

But then this plugin will need to enable parameters the build.

By the way, my plugin will be available in Atlassian Marketplace within a few days.

Unit Test failure on OSX

Unit tests failing on OSX:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running InjectedTest
Picking up existing exploded jenkins.war at /Users/DALEK/stash-pullrequest-builder-plugin/./target/jenkins-for-test
Jul 01, 2015 10:54:32 PM org.mortbay.log.Slf4jLog info
INFO: Logging to org.slf4j.impl.JDK14LoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
Jul 01, 2015 10:54:33 PM org.mortbay.log.Slf4jLog info
INFO: jetty-6.1.26
Jul 01, 2015 10:54:33 PM org.mortbay.log.Slf4jLog info
INFO: NO JSP Support for , did not find org.apache.jasper.servlet.JspServlet
Jul 01, 2015 10:54:33 PM org.mortbay.log.Slf4jLog info
INFO: Started [email protected]:49599
Jul 01, 2015 10:54:33 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Jul 01, 2015 10:54:35 PM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Jul 01, 2015 10:54:35 PM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Jul 01, 2015 10:54:35 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Jul 01, 2015 10:54:35 PM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Jul 01, 2015 10:54:35 PM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Jul 01, 2015 10:54:36 PM net.java.sezpoz.Index$LazyIndexIterator peek
WARNING: possible endless loop getting index for interface hudson.Extension from classLoader hudson.PluginManager$UberClassLoader
Jul 01, 2015 10:54:36 PM net.java.sezpoz.Index$LazyIndexIterator peek
WARNING: possible endless loop getting index for interface hudson.Extension from classLoader hudson.PluginManager$UberClassLoader
Jul 01, 2015 10:54:37 PM net.java.sezpoz.Index$LazyIndexIterator peek
WARNING: possible endless loop getting index for interface hudson.Extension from classLoader hudson.PluginManager$UberClassLoader
Jul 01, 2015 10:54:38 PM jenkins.InitReactorRunner$1 onTaskFailed
SEVERE: Failed GitTool.onLoaded
java.lang.Error: java.lang.reflect.InvocationTargetException
    at hudson.init.InitializerFinder.invoke(InitializerFinder.java:124)
    at hudson.init.InitializerFinder$TaskImpl.run(InitializerFinder.java:184)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:259)
    at jenkins.model.Jenkins$7.runTask(Jenkins.java:899)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:187)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at hudson.init.InitializerFinder.invoke(InitializerFinder.java:120)
    ... 8 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
    at com.thoughtworks.xstream.core.util.OrderRetainingMap.entrySet(OrderRetainingMap.java:77)
    at java.util.HashMap.putMapEntries(HashMap.java:511)
    at java.util.HashMap.putAll(HashMap.java:784)
    at com.thoughtworks.xstream.core.util.OrderRetainingMap.<init>(OrderRetainingMap.java:36)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(FieldDictionary.java:135)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldsFor(FieldDictionary.java:76)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:127)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:143)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:102)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
    at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:898)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:887)
    at com.thoughtworks.xstream.XStream.toXML(XStream.java:860)
    at hudson.XmlFile.write(XmlFile.java:183)
    at hudson.model.Descriptor.save(Descriptor.java:758)
    at hudson.plugins.git.GitTool.onLoaded(GitTool.java:106)
    ... 13 more

Exception in thread "pool-2-thread-3" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Exception in thread "pool-2-thread-10" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Exception in thread "pool-2-thread-1" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Exception in thread "pool-2-thread-7" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Exception in thread "pool-2-thread-2" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Exception in thread "pool-2-thread-5" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Jul 01, 2015 10:54:38 PM org.mortbay.log.Slf4jLog info
INFO: jetty-6.1.26
Jul 01, 2015 10:54:38 PM org.mortbay.log.Slf4jLog info
INFO: NO JSP Support for , did not find org.apache.jasper.servlet.JspServlet
Jul 01, 2015 10:54:38 PM org.mortbay.log.Slf4jLog info
INFO: Started [email protected]:49634
Jul 01, 2015 10:54:39 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Jul 01, 2015 10:54:39 PM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Jul 01, 2015 10:54:39 PM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Jul 01, 2015 10:54:39 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Jul 01, 2015 10:54:39 PM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Jul 01, 2015 10:54:39 PM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Jul 01, 2015 10:54:39 PM net.java.sezpoz.Index$LazyIndexIterator peek
WARNING: possible endless loop getting index for interface hudson.Extension from classLoader hudson.PluginManager$UberClassLoader
Jul 01, 2015 10:54:39 PM net.java.sezpoz.Index$LazyIndexIterator peek
WARNING: possible endless loop getting index for interface hudson.Extension from classLoader hudson.PluginManager$UberClassLoader
Jul 01, 2015 10:54:39 PM net.java.sezpoz.Index$LazyIndexIterator peek
WARNING: possible endless loop getting index for interface hudson.Extension from classLoader hudson.PluginManager$UberClassLoader
Jul 01, 2015 10:54:40 PM jenkins.InitReactorRunner$1 onTaskFailed
SEVERE: Failed GitTool.onLoaded
java.lang.Error: java.lang.reflect.InvocationTargetException
    at hudson.init.InitializerFinder.invoke(InitializerFinder.java:124)
    at hudson.init.InitializerFinder$TaskImpl.run(InitializerFinder.java:184)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:259)
    at jenkins.model.Jenkins$7.runTask(Jenkins.java:899)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:187)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at hudson.init.InitializerFinder.invoke(InitializerFinder.java:120)
    ... 8 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
    at com.thoughtworks.xstream.core.util.OrderRetainingMap.entrySet(OrderRetainingMap.java:77)
    at java.util.HashMap.putMapEntries(HashMap.java:511)
    at java.util.HashMap.putAll(HashMap.java:784)
    at com.thoughtworks.xstream.core.util.OrderRetainingMap.<init>(OrderRetainingMap.java:36)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(FieldDictionary.java:135)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldsFor(FieldDictionary.java:76)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:127)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:143)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:102)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
    at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:898)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:887)
    at com.thoughtworks.xstream.XStream.toXML(XStream.java:860)
    at hudson.XmlFile.write(XmlFile.java:183)
    at hudson.model.Descriptor.save(Descriptor.java:758)
    at hudson.plugins.git.GitTool.onLoaded(GitTool.java:106)
    ... 13 more

Exception in thread "pool-6-thread-15" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Exception in thread "pool-6-thread-9" Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 9.195 sec <<< FAILURE!
Exception in thread "pool-6-thread-5" Running stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClientTest
Exception in thread "pool-6-thread-2" Exception in thread "pool-6-thread-14" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Exception in thread "pool-6-thread-12" java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:191)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.224 sec
Running stashpullrequestbuilder.stashpullrequestbuilder.stash.StashPullRequestResponseValueRepositoryTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.01 sec

Results :

Tests in error: 
  org.jvnet.hudson.test.JellyTestSuiteBuilder$JellyTestSuite(org.jvnet.hudson.test.junit.FailedTest): java.lang.Error: java.lang.reflect.InvocationTargetException
  testCliSanity(org.jvnet.hudson.test.PluginAutomaticTestBuilder$CliSanityTest): java.lang.Error: java.lang.reflect.InvocationTargetException

Tests run: 8, Failures: 0, Errors: 2, Skipped: 0

Option to not comment on pull request

I would like there to be an option to not comment on the pull request at all. In my use case, the comments from this plugin are redundant. I am happy to make the changes needed, but I would need someone to point me in the right direction. I am not certain where in the code the comments are being added.

Comments URL Has Changed

I upgraded to plugin 1.3.1 after seeing this error in the logs:

Jul 22, 2015 10:35:02 AM FINEST stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient
PR-POST-REQUEST:http://stash.us.com/rest/api/1.0/projects/CMS/repos/imps/pull-requests/129/comments with: [*BuildStarted* **IMPS_pull_request**] ec91d4b382a46fb46d5d9401f9e61c2e0d995987 into 0d3a6d03ba29d01a0caba1deaaf77a15f4acd987
Jul 22, 2015 10:35:02 AM INFO stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient postRequest
API Request Response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://stash.us.com/rest/api/1.0/projects/CMS/repos/imps/pull-requests/129/comments">here</a>.</p>
<hr>
<address>Apache/2.2.12 (Linux/SUSE) Server at stash.us.com Port 80</address>
</body></html>

The error still persists in 1.3.1. My stash instance no longer receives any comments, or any other interaction for that matter and the Jenkins job does not run. I am not sure how to find the version number of my stash instance, although the REST API URL says 1.0.

weird race condition when getting SHA

Hi
I am seeing a weird issue where the incorrect SHA is populated when getting commit for the latest PR.

In this example the SHA is incorrect which caused the build to fail.

Building in workspace /var/lib/jenkins/jobs/MYREPO/workspace

git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
git config remote.origin.url ssh://git@stashserver:7999/pro/MYREPO.git # timeout=10
Fetching upstream changes from ssh://git@stashserver:7999/pro/MYREPO.git
git --version # timeout=10
using GIT_SSH to set credentials
git -c core.askpass=true fetch --tags --progress ssh://git@stashserver:7999/pro/MYREPO.git +refs/pull-requests/:refs/remotes/origin/pr/
git rev-parse refs/remotes/origin/pr/227/from^{commit} # timeout=10
git rev-parse refs/remotes/origin/origin/pr/227/from^{commit} # timeout=10
*Checking out Revision 893f4b0ff1caa40f4f8afe36386de5ec10f972a3 (refs/remotes/origin/pr/227/from)
git config core.sparsecheckout # timeout=10
git checkout -f 893f4b0ff1caa40f4f8afe36386de5ec10f972a3 not the correct sha

git rev-list 893f4b0ff1caa40f4f8afe36386de5ec10f972a3 # timeout=10

If I comment the PR with "Test this please" then the correct SHA gets populated.

Building in workspace /var/lib/jenkins/jobs/MYREPO/workspace

git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
git config remote.origin.url ssh://git@stashserver:7999/pro/MYREPO.git # timeout=10
Cleaning workspace
git rev-parse --verify HEAD # timeout=10
Resetting working tree
git reset --hard # timeout=10
git clean -fdx # timeout=10
Fetching upstream changes from ssh://git@stashserver:7999/pro/MYREPO.git
git --version # timeout=10
using GIT_SSH to set credentials
git -c core.askpass=true fetch --tags --progress ssh://git@stashserver:7999/pro/MYREPO.git +refs/pull-requests/:refs/remotes/origin/pr/
git rev-parse refs/remotes/origin/pr/227/from^{commit} # timeout=10
git rev-parse refs/remotes/origin/origin/pr/227/from^{commit} # timeout=10
Checking out Revision 40ef87726c4aa1e773bbf09b54f48413bed60f8c (refs/remotes/origin/pr/227/from)
git config core.sparsecheckout # timeout=10
git checkout -f 40ef87726c4aa1e773bbf09b54f48413bed60f8c
git rev-list 893f4b0ff1caa40f4f8afe36386de5ec10f972a3 # timeout=10

Has anyone seen this? Could this be a bug or something I'm missing?
Thanks,
Rob

Only run the jenkins job if the "test this please" phrase is in the comment

I would like to create two types of pull request jobs. One would run every time a pull request is created and modified and the other would only run if requested. I'm thinking that if this plugin could be configured to only run if the "test this please" comment existed in stash, then I would be able to fire off the second job on an as needed basis.

It would also be nice to have PR #8 so that both jobs could have their own "test this please" comment.

Icon with link to Stash in Build History column

With more secure Jenkins configuration links to stash in the Build History column are not "clickable". It would be useful to (always, optionally?) have a separate icon with a link to Stash.

It could be done manually with Groovy Postbuild Plugin, but support that that out of the box would be handy.

Variable ${pullRequestCommit} is not set

As described in this thread, the variable ${pullRequestCommit} is not set: #37

According to the answer this should be in the current release, but we have the same problem with the 1.4.2 release.

Enhancement: Update/Removed queued builds for PR

If a PR is updated (which might happen often if rebuild if target branch changes option is used, or builds take a long time) it would be better to search the build queue for any queued jobs matching that PR and either update it or remove the queued job before adding a new one. That is to say there should only be one queued build per PR, as only the most recent is usually of interest.
There are API that should make this possible, that can be called before job.scheduleBuild2. isInQueue and getQueueItem look the most relevant.

Allow suppressing "Build started" and "Build success"/"Build failed"

For cases where we have an alternate method of reporting the result of a build, it would be nice to suppress the stash-pullrequest-builder-plugin build comments. My use case: I have a script that is triggered by a jenkins job, which comments back on the PR with the result of a javascript lint. The comments from this plugin are unnecessary noise at that point - there are probably other cases where this is applicable, too.

I can put up a PR for this myself - let me know if you think this is a desirable feature? It would be configurable in jenkins, and the suppression would be opt-in.

Accessing ${sourceBranch} and ${targetBranch}

Hi,

I'm using stath-pullrequest-builder-plugin-1.3.1 on Jenkins-1.624 with git-1.7.12.4 and can't seem to access any of those variables.
I have configured a job trying to poll a repo for PRs and build the merge of the source branch with the target branch. Relevant configuration follows:

Source Code Management -> Git -> Repositories:
* Repository URL: https://<user>@<repo>.git 
* Name: origin
* Refspec: +refs/pull-requests/*:refs/remotes/origin/pr/*
* Branches to Build: */${sourceBranch}

Source Code Management -> Additional Behaviours -> Merge Before Build:
* Name of Repository: origin
* Branch to Merge: ${targetBranch}
* Merge Strategy: default
* Fast-forward mode: -ff

When manually triggering the job, I'm getting the following output (note vars like have been manually edited for this post):

Started by user anonymous
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/jobs/<JOB>/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://<REPO># timeout=10
Fetching upstream changes from https://<REPO>
 > git --version # timeout=10
using .gitcredentials to set credentials
 > git config --local credential.helper store --file=/tmp/git5169754694021595086.credentials # timeout=10
Setting http proxy: <PROXY>
 > git -c core.askpass=true fetch --tags --progress https://<REPO> +refs/pull-requests/*:refs/remotes/origin/pr/*
 > git config --local --remove-section credential # timeout=10
Seen branch in repository origin/foo
Seen branch in repository origin/master
Seen branch in repository origin/pr/52/from
Seen branch in repository origin/pr/52/merge
Seen branch in repository origin/release/1.8.10
Seen branch in repository origin/release/1.8.11
Seen branch in repository origin/release/1.8.12
Seen branch in repository origin/release/1.8.13
Seen branch in repository origin/release/1.8.14
Seen branch in repository origin/release/1.8.14.1
Seen branch in repository origin/release/1.8.8
Seen branch in repository origin/release/1.8.9
Seen branch in repository origin/test
Seen 13 remote branches
Merging Revision 754018c35fb9994f5bae371afdbc4069ac46293e (origin/foo, origin/pr/52/from, origin/master) to origin/${targetBranch}, UserMergeOptions{mergeRemote='origin', mergeTarget='${targetBranch}', mergeStrategy='default', fastForwardMode='--ff'}
 > git rev-parse origin/${targetBranch}^{commit} # timeout=10
FATAL: Command "git rev-parse origin/${targetBranch}^{commit}" returned status code 128:
stdout: origin/${targetBranch}^{commit}

stderr: fatal: ambiguous argument 'origin/${targetBranch}^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

hudson.plugins.git.GitException: Command "git rev-parse origin/${targetBranch}^{commit}" returned status code 128:
stdout: origin/${targetBranch}^{commit}

stderr: fatal: ambiguous argument 'origin/${targetBranch}^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1600)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1576)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1572)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1233)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1245)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:607)
    at hudson.plugins.git.GitAPI.revParse(GitAPI.java:316)
    at hudson.plugins.git.extensions.impl.PreBuildMerge.decorateRevisionToBuild(PreBuildMerge.java:64)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:955)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1044)
    at hudson.scm.SCM.checkout(SCM.java:485)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1277)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:610)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:532)
    at hudson.model.Run.execute(Run.java:1741)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:381)
Finished: FAILURE

If instead I leave empty Branches to Build: and set Branch to Merge: master, my build succeeds.
Am I doing something wrong? Can someone help me out here?

Comments trigger a new build

Hey,

This plugin works great for us, but with one exception - when someone raises a pull request and there are comments left, the plugin seems to detect this as a change and does another build. This then causes quite a lot of noise/emails when really we only want it to build when it's raised and then again if there's another push.

Am I missing something with the configuration?

Cannot use ssh or https in the "Stash Host" field ?

I used this plug-in with a dummy stash installation, and it is working well, but the access used http.
Not, I am going back to my real project.
My git repository URL looks ssh://git@git.<stashURL>:7999/<project>/<repo>.git and it is working well. But I want to use the plugin (1.3.1 version), I cannot manage to find what to put in theStash Host field.

  • I had java.lang.IllegalStateException: unsupported protocol: 'ssh'
  • I also had Unrecognized SSL message, plaintext connection?
  • git.<stashURL>:7999 gives java.lang.IllegalStateException: unsupported protocol
  • https://git.<stashURL>:7999 gives java.lang.NullPointerException
  • I also tried with nothing in the field, hoping it will be able to get it from the git URL, but it gives java.lang.IllegalArgumentException: host parameter is null

What am I supposed to put here in this case ? Is this supported ?
Thanks in advance for your help.

Post Build Tasks blocking concurrent builds

If I am running basically a PR build/merge job on multiple nodes, the post build tasks wait on any previous jobs running before they will finish. In the case of PR builds, there is not always the need to wait on previous builds when running concurrently on multiple nodes since they may be from different PRs. Would it be possible to add an option to not have the post build tasks wait on checkpoints?

Doesn't work with forks

This appears to only work if the PR is from a branch in the same repository. Would it be possible to make this work with PRs from forks as well? I'm not much of a Java dev, but I'd be willing to take a stab at it if you can point me in the right direction.

Thanks

Control notifications sent back to Stash

My Jenkins setup involves a fairly complex pipeline of jobs, of which I only wish one to be triggered by pull request changes. This job will in turn trigger other downstream jobs.

This conflicts with the design of this plugin, in that a notification is returned to the Stash pull request API as soon as this trigger job is complete. This is a problem, as it means a "success" notification is returned before Jenkins has built or tested anything on the branch. This could result in the pull request being marked good while builds have failed in the background.

I would like for there to be config options that turn on or off the notifications sent to Stash.

(pull request incoming)

Branches with slashes confuse the job

I have a branch named "bugfix/fix-a-bug" and when I created a pull request, this plugin correctly started a build. But then it failed because it couldn't find any changes to the branch. It turns out that it was using "fix-a-bug" as the branch name instead of "bugfix/fix-a-bug".

This plugin needs to handle branches that have '/' in them.

NullPointer since 1.3.0

I've upgraded to 1.3.0, and, I believe, configured according to instructions.

However, I'm faced with:

WARNING: stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger.run() failed for hudson.model.FreeStyleProject@2de62290[rmq_develop]
java.lang.NullPointerException

Is there any way to get a stacktrace, or some sort of clue exactly what is missing?

(Stash v3.1.1)

If there are more than 25 open pull requests - builds are not triggred for pull requests beyond 25th

We had a maintenance and restarted jenkins - after that jobs that were triggered by the plugin no longer are. Nothing apparent changed on the jobs/jenkins or stash side. Logs are not very conclusive to me (see below). The plugin is triggered every minute as before.

Aug 19, 2015 10:42:00 PM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashPullRequestsBuilder run
Build Start.
Aug 19, 2015 10:42:00 PM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashRepository getTargetPullRequests
Fetch PullRequests.
Aug 19, 2015 10:42:01 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:02 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:02 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:02 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:03 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:03 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:03 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:03 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:04 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:04 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:04 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:05 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:05 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:05 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:06 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:06 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:06 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:06 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:07 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:07 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:08 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:08 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:08 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:09 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:09 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:09 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:09 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:10 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:10 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:10 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:11 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:11 PM WARNING org.apache.commons.httpclient.HttpMethodBase getResponseBody
Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
Aug 19, 2015 10:42:11 PM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashBuildListener onStarted
BuildListener onStarted called.
Aug 19, 2015 10:42:11 PM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashBuildListener onStarted
BuildListener onStarted called.

Dependencies on other pull requests?

My team is using a gradle/mavenish workflow where we have internal libraries that have their own jenkins builds.

Sometimes, when we commit a change, it's dependent on something upstream being merged first. Is it possible to add support for dependent pull requests? I.e., "don't try to build this PR until the following PRs have merged"?

Force the refs to be updated

I experimented strange behaviors because in some cases, the plug-in was able to detect a new PR, but not to checkout the correct branch. I asked here : http://stackoverflow.com/questions/31458668/why-is-there-a-delay-between-a-pull-request-and-the-possibility-to-fetch-it-in, and someone from Stash explained the reason. It seems that you should call PullRequestService.canMerge before fetching. What do you thing ?

A temporary workaround is to force the update by exploring the PR in the UI, but it is not very convenient.

Variable ${pullRequestCommit} was removed

The documentation states that when using the "Notify Stash Instance" post-build step, you should use the variable ${pullRequestCommit} as Commit SHA-1 value.
However that variable has been removed in the latest release.
Is there a specific reason for this, or could you just bring that variable back?
It would be much appreciated.

Plugin not polling Stash

Hi, I have a Jenkins instance where this handy plugin is not polling stash. The job has is configured with a cron set to every minute (* * * * *), but it does not look for new pull requests as they are created/updated. The kicker is that everything works great when Jenkins is restarted; with the job connecting to Stash, reading the comments to kick off a build, and reporting results back. After looking at the logs it appears that the plugin is not polling correctly if at all. Every once in a while (at seemingly random times, sometimes hours, sometimes minutes apart) the logs will show BuildListener onStarted called. and nothing following that. After a restart the logs are populated as expected with request messages and statements that look correct. Any ideas on what may be going on?

Didn't get a 200 response from Stash PR POST

I don't understand why I'm getting this error, the 'started build' commet gets created ok but because the plugin doesn't get a 200 response from stash the build never happens

The error log says the response is 'Created' with message; {"id":256,"version":0,"text":"[*BuildStarted* **test-jenkins-PR**] 81c0256c157649c31daed0333de6add965f744c9 into 5471d06841458a84deb9d1c20d29289c3165d315"...

According to the stash Documentation a successful PR comment post will return a 201 response header
https://developer.atlassian.com/static/rest/stash/3.11.3/stash-rest.html#idp1448560

Doesn't queue the PR builds on the same project, only builds the newest

We currently pull every 5 minutes to see if a PR is created. When we have to 2 different PRs on the same project with different branches created/updated with in the same 5 minutes it only builds the latest PR.

Need it to queue all PR builds that it finds. Not just the latest. As we can create/update multiple PRs between pulls.

Fetch Stash credentials from Global Credentials support

It would be nice if the credentials needed to fetch the PR information from Stash could be configured in Global Credentials and the plugin fetches the information from there. This is especially relevant where different users have different roles and Jenkins Bot user password shall not be known to all users who configured Jenkins jobs.

Building specific targeted branches

When using the "Build PR targetting only these branches" parameter, the plugin will only build the first branch specified.

Test Cases:

  • unstable , dev, master
  • unstable,dev,master
  • unstable, dev
  • unstable,dev

Skipping Message:

Jan 06, 2016 1:07:02 PM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository isBuildTarget
INFO: Skipping PR: 58 as targeting branch: dev
Jan 06, 2016 1:07:02 PM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository isBuildTarget
INFO: Skipping PR: 59 as targeting branch: master

The code looks as though it should perform as expected. Is there something I'm missing?

java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
Jenkins ver. 1.625.3.1 (CloudBees Jenkins Enterprise 15.11)

Poll fails with NullPointerException

Hello,

I've tried to set up a job using the Stash pullrequest builder plugin but it fails to poll Stash with a NullPointerException:

Oct 13, 2015 5:02:01 PM WARNING hudson.triggers.Trigger checkTriggers stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger.run() failed for hudson.maven.MavenModuleSet@2aa7eb8[my-job-name]
java.lang.NullPointerException
at stashpullrequestbuilder.stashpullrequestbuilder.StashRepository.postBuildStartCommentTo(StashRepository.java:72)
at stashpullrequestbuilder.stashpullrequestbuilder.StashRepository.addFutureBuildTasks(StashRepository.java:77)
at stashpullrequestbuilder.stashpullrequestbuilder.StashPullRequestsBuilder.run(StashPullRequestsBuilder.java:31)
at stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger.run(StashBuildTrigger.java:168)
at hudson.triggers.Trigger.checkTriggers(Trigger.java:282)
at hudson.triggers.Trigger$Cron.doRun(Trigger.java:221)
at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:51)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

I'm guessing that the method postPullRequestComment encountered an UnsupportedEncodingException or an IOException and returned null. I don't understand the benefit of this behavior however, since the upstream error message is lost and no check is done to see if the method suceeded or not.

I was hoping you could clarify that for me. The plugin works perfectly with a similar configuration on my 'test server', which is a virtual machine running jenkins and stash. I feel like I won't be able to move forward without a meaningful error message.

I'm working with Jenkins v1.627 and the version 1.3.1 of the plugin.

Best regards.

Basic Auth username not respected

So I got the plugin working, but when I added more jobs for the rest of my repos, they all started using a basic auth user of 'Atlassian Stash' instead of the user I've specified in the jobs (jenkins).

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.