User Tools

Site Tools


projects:bitbucket:pullrequestplugin

Bitbucket Server Repository Pull Request Hook Plugin

Planned features

  • Multiple URLs
  • Support for HTTPS
  • Internationalization

Introduction

The plugin provides the following functionality:

  • Notifying 3rd party services via REST interface about the changes in the project Pull Requests
  • Notification on:
    • PR creation/edit
    • PR decline
    • PR merge
    • New/Edit/Delete comment in the PR
  • Per-repository configuration via 'repository hooks' tab
  • Accessible by the repository administrators
  • The following HTTP operations are supported:
    • POST
    • GET
    • PUT
    • DELETE

Usage

Templating

Several variables can be passed by the message URL or body. There is a special variable containing comma separated list of available variables: ${all_keys}

Authorization

There is no dedicated field for authorization. One can add authorization header into 'headers'. In such case the field will look like:

Please visit wikipedia to learn how to construct basic auth header.

For Jenkins it is recommended to use Build Token Root Plugin. It allows using anonymous request + build token (think of API key).

Example 1

  1. Create Jenkins job “Bitbucket Capture”
    1. Add String Parameter ALL
    2. Add Token BBBUILD in Build Triggers Trigger builds remotely (e.g., from scripts)
  2. Check if the job is working
    1. Trigger job manually using your browser's private mode

Entering URL will take you to an empty page. Back in Jenkins you should see that the job was triggered and parameter is successfully passed:

  1. Add more String Parameters to the Jenkins job:
    1. ACTION
    2. PR_ID
    3. REPO
    4. PROJECT
  2. Configure Bitbucket Server
    1. Ensure that the plugin is installed.
    2. Enter any repository Settings, then Hooks
    3. Enable Pull Request Hook
    4. Enter URL http://localhost:8080/buildByToken/buildWithParameters?token=BBBUILD&job=Bitbucket%20Capture&ALL=${all_keys}&ACTION=${action}&PR_ID=${pr_id}&REPO=${repo}&PROJECT=${project}
    5. Enable all triggers
    6. Save

  1. Test connection
    1. Create pull request
    2. Add a comment

After that you should notice that a new builds were run. Inspect those builds parameters.

Extras

Jenkins job config.xml:

<project>
  <actions/>
  <description/>
  <keepDependencies>false</keepDependencies>
  <properties>
    <hudson.model.ParametersDefinitionProperty>
      <parameterDefinitions>
        <hudson.model.StringParameterDefinition>
          <name>ALL</name>
          <description/>
          <defaultValue/>
        </hudson.model.StringParameterDefinition>
      </parameterDefinitions>
    </hudson.model.ParametersDefinitionProperty>
  </properties>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <authToken>BBBUILD</authToken>
  <triggers/>
  <concurrentBuild>false</concurrentBuild>
  <builders/>
  <publishers/>
  <buildWrappers/>
</project>

Displaying Log

There is a button in the configuration dialog that leads to a log. Communications are logged per-repository.

Notes

  • Connection time-out is set to 5 seconds

Test scenarios

Configuration

  • Entering incorrect URL
    • https:\\123.com
    • 45434.com
    • http:
      space .com
  • Entering incorrect header data
    • without colon
    • empty lines

Core

  • Enable all notification types and check them one-by one
  • Set all possible variables in body and check if it is valid for all notification types
  • Use basic-auth header

Weblog

  • Accessing non-existing log
  • Accessing existing log by admin of other project
  • Accessing log with non-configured plugin for given repository
  • Accessing log when non-existing URL is set in config
projects/bitbucket/pullrequestplugin.txt · Last modified: 2016/04/25 22:08 by mkucia