Child pages
  • Bitbucket Push And Pull Request Plugin

Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 21 Next »



Plugin Information

View Bitbucket Push and Pull Request on the plugin site for more information.

Requirements

This plugin requires a Jenkins v2.138.2 or later and supports

  • Bitbucket Cloud rest api v2.x+ and later
  • Bitbucket Server 5.14+ and later

Plugin for Jenkins v2.138.2 or later, that triggers builds on Bitbucket's push and pull requests. It's based on the Sazo's fork (https://github.com/sazo/bitbucket-plugin) of the official Bitbucket Plugin (https://plugins.jenkins.io/bitbucket).

The new features introduced by Bitbucket Push and Pull Request are:

  • improved support of pushs for Bitbucket cloud (rest api v2.x+) and Bitbucket server (5.14+)
  • support of pull requests for Bitbucket cloud (rest api v2.x+) (thanks Sazo)
  • usage of Gson instead of net.sf.json.JSONObject (blacklisted starting from Jenkins 2.102+)
  • Introduction of Models and security improvements


The new features introduced by Bitbucket Push and Pull Request are:
  •  improved support of pushs for Bitbucket cloud (rest api v2.x+) and Bitbucket server (5.14+)
  • support of pull requests for Bitbucket cloud (rest api v2.x+) (thanks Sazo)
  • usage of Gson instead of net.sf.json.JSONObject (blacklisted starting from Jenkins 2.102+)
  • introduction of Models and security improvements

This plugin supports:
  • push and pull requests for Bitbucket cloud rest api v2.x+ and later
  • push for Bitbucket server 5.14+ and later (Experimental)

Configuration

Configure the webhook

In case you are using Bitbucket Cloud, configure your Bitbucket repository adding a webhook in the settings page. In the URL field (see image, point A) add your JENKINS_URL followed by "/bitbucket-hook/" (for example "https://my-jenkins.on-my-planet-far-away.com/bitbucket-hook/") Credentials for the webhook endpoint are not required, the trailing slash is mandatory. For more infos please consult the resource https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html.

If you are using Bitbucket Server, follow these instructions: https://confluence.atlassian.com/bitbucketserver/managing-webhooks-in-bitbucket-server-938025878.html

Configure your Jenkins job

1. Configure the Bitbucket Repository under the Source Code Management with your credentials.


2. Now activate the plugin in your job selecting the "Build with Bitbucket Push and Pull Request Plugin" option in the Build Triggers pane.

Code snippets

Dsl jobs
job('example-pull-request-created') {
  	triggers{
  		bitbucketPullRequestCreatedAction()
  	}
  	scm {
		git {
		    remote {
		        url("https://git.company.domain/scm/~username/telegram.git")
		    }
		}
	}
    steps {
        shell('echo START pull request created')
    }
}

job('example-pull-request-updated') {
  	triggers{
  		bitbucketPullRequestUpdatedAction()
  	}
  	scm {
		git {
		    remote {
		        url("https://git.company.domain/scm/~username/telegram.git")
		    }
		}
	}
    steps {
        shell('echo START pull request updated')
    }
}

// bitbucketPullRequestApprovedAction(boolean onlyIfReviewersApproved)
job('example-pull-request-approved') {
  	triggers{
  		bitbucketPullRequestApprovedAction(false)
  	}
  	scm {
		git {
		    remote {
		        url("https://git.company.domain/scm/~username/telegram.git")
		    }
		}
	}
    steps {
        shell('echo START pull request approved')
    }
}

// bitbucketRepositoryPushAction(boolean triggerAlsoIfTagPush, String allowedBranches)
job('example-push') {
  	triggers{
  		bitbucketRepositoryPushAction(false, "")
  	}
  	scm {
		git {
		    remote {
		        url("https://git.company.domain/scm/~username/telegram.git")
		    }
		}
	}
    steps {
        shell('echo START push')
    }
}
Pipeline script
properties([
    pipelineTriggers([
        [
            $class: 'BitBucketPPRTrigger',
            triggers : [
                [
                    $class: 'BitBucketPPRPullRequestTriggerFilter',
                    actionFilter: [
                        $class: 'BitBucketPPRPullRequestCreatedActionFilter'
                    ]
                ]
            ]
        ]
    ])
])
node {
	def sourceBranch = ""
        def targetBranch = ""
        try{
            sourceBranch = "${BITBUCKET_SOURCE_BRANCH}";
            targetBranch = "${BITBUCKET_TARGET_BRANCH}";
        }catch(e){}

        if(sourceBranch == ""){
            sourceBranch = 'development'
        }

        if(targetBranch == ""){
            targetBranch = 'master'
        }

        checkout changelog: true, poll: true, scm: [
            $class: 'GitSCM',
            branches: [
                [name: '*/'+sourceBranch]
            ],
            doGenerateSubmoduleConfigurations: false,
            extensions: [
                 [
                    $class: 'PreBuildMerge',
                    options: [
                        fastForwardMode: 'FF',
                        mergeRemote: 'origin',
                        mergeStrategy: 'recursive',
                        mergeTarget: ''+targetBranch
                    ]
                ]
            ],
            submoduleCfg: [],
            userRemoteConfigs: [
                [
                    url: 'https://[user]@bitbucket.org/[org]/[repo].git']
                ]
            ]


        echo 'Some build steps'

}


Roadmap

  • introduce pullrequests for Bitbucket server 5.14+ and later
  • improve DSL pipelines scripting

Change Log

1.6.0 (2019-04-29)

Full Changelog

Implemented enhancements:

  • split methods of io.jenkins.plugins.bitbucketpushandpullrequest.BitBucketPPRJobProbe to allow unit tests

Closed issues:

  • Improvements#20 Add trigger for pull request merged
  • Improvements#14 Pattern for allowed branches
  • Improvements#5 Improve support for BitBucket Server push

Merged pull requests:

  • [develop] Remove deprecated username field from payload #17 by macghriogair
  • [develop] add support for pattern matching on branches #18 by macghriogair
  • [develop] Add support for merged pull requests #21 by cdelmonte-zg

1.5.0 (2019-04-11)

Full Changelog

Implemented enhancements:

  • split methods of io.jenkins.plugins.bitbucketpushandpullrequest.BitBucketPPRJobProbe to allow unit tests

Closed issues:

  • Improvements#10 add ssh uri matching for git clone
  • Improvements#12 No change-logs or description of features
  • Improvements#5 Improve support for BitBucket Server push

Merged pull requests:

  • [dev] gitignore more project specific entries #13 by macghriogair


  • No labels