×
Find plugins

Stash Pullrequest Builder
1.7.0Minimum Jenkins requirement: 1.625.3ID: stash-pullrequest-builder

This plugin builds pull requests from an Atlassian Stash instance and will report the test results.

Stash Pull Request Builder Plugin

This Jenkins plugin builds pull requests from an 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:

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

Creating a Job
Source Code Management

Select Git then configure:

  • Repository URL:

    git@example.com:/${destinationRepositoryOwner}/${destinationRepositoryName}.git
  • Advanced -> 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. Blank for all.
  • Rebuild if destination branch changes:
  • Build only if Stash reports no conflicts:
  • Build only if PR is mergeable:
  • CI Skip Phrases: default: "NO TEST"
  • Only build when asked (with test phrase):
  • CI Build Phrases: default: "test this please"

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 possibly also without conflicts. There are advanced options in the build trigger for both of these.

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.
Notify Stash Instance

If you have enabled the 'Notify Stash Instance' Post-build Action and also enabled the 'Merge before build' extension you need to add '${pullRequestCommit}' as Commit SHA-1. Otherwise you'll notify Stash with the commit hash resulting from the merge which isn't known to Stash (since it's merged locally).

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.

Versions

Release notes;

v1.6.0
  • Bug fix - Jenkins issue #30558 - sockets causing problems with hanging triggers
  • Bug fix - include default parameter values in build queue
  • Added project name to log messages
v1.5.3
  • Branch name filters can now be regular expressions
  • Support all build states (now all states are reported, not just success or everything else as failure in the build PR comment)
v1.5.2
  • Fix PR branch filters
v1.5.1
  • Added ability to only keep the most recent PR status comment
  • Logging improvements
  • Ability to limit PR builds to specified target branches only
v1.5.0
  • Added credentials support - this is a breaking change, please add a username/password credential for the user you want PR build comments to be posted from. Old builds will fail until you update them with the right credentials from the credentials plugin. 
  • Fixup branch & ref specs in git config - again this is a breaking change and you should update your git configuration (URL, ref spec & branch specifier), please see the updated README  
v1.4.2
  • Fix bug with Stash response code handling 
v1.4.1
  • Better error handling when Stash returns 200/OK response
  • Added support for custom parameters in the 'test this please' comment
  • Option to ignore SSL certificates (useful if you dont have proper certificates with your Stash instance)
  • Fixes for PR pagination
v1.4.0
  • Added build duration to build finished message in PR - useful for tracking runtimes/test overheads added in PRs. 
  • Improved Stash polling
  • Better JSON handling 
  • Added better support for the notify Stash plugin to only tag the source commit SHA1
  • Bugfixes
v1.3.1
  • Use Git SCM as provider for hostname and credentials needed for the pull request builder
  • Now it is also possible to verify pull requests from another fork (while previously it would only work in the same repository, or at least with the merge before build feature). Prerequisite is that you add +refs/pull-requests/:refs/remotes/origin/pr/ as refspec.
  • Additionally you can filter on the target branch which makes you able to restrict checking pull requests on a specific (release) branch.
  • Support for global environment variables has been added.
v1.2.0
  • Added post build custom comment support
  • Marked credentials plugin as required dependency for upcoming v1.3.0 release with Credentials support
v1.1.0
  • Added ability to customise the build phrase (change from the default of 'test this please')
  • Added ability to only have PR built if its merge-able (i..e has been approved)
  • Added ability to only have PR built if its not conflicted
  • Added check to only build PR on comment (don't auto build) based on build phrase (default is 'test this please')
v1.0.1
  • Fix bug with passing branch names with a '/'
  • Reduce logging verbosity
v1.0.0
  • Initial release
ArchivesGet past versions
Labels