GithubHelp home page GithubHelp logo

eddiriarte / bitbucket-push-and-pull-request-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jenkinsci/bitbucket-push-and-pull-request-plugin

0.0 2.0 0.0 137 KB

Plugin for Jenkins v2.138.2 or later, that trigger builds on Bitbucket's push and pull requests.

Home Page: https://plugins.jenkins.io/bitbucket-push-and-pull-request

License: MIT License

Java 100.00%

bitbucket-push-and-pull-request-plugin's Introduction

Bitbucket Push and Pull Request Plugin

Plugin for Jenkins v2.138.2 or later, that trigger builds on Bitbucket's push and pull requests. It's based on the Sazo's fork (https://github.com/sazo/bitbucket-plugin) of the 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

Bitbucket Push and Pull Request supports the

  • Bitbucket cloud rest api v2.x+ and later
  • Bitbucket server 5.14+ and later

Before you start... Bitbucket Push And Pull Request Plugin will not work if the old Bitbucket plugin https://plugins.jenkins.io/bitbucket is still installed. So, please de-install from Jenkins the previous Bitbucket plugin if you want to use this new one.

For infos about the plugin's configuration please visit the webpage https://plugins.jenkins.io/bitbucket-push-and-pull-request

Environment variables

Environment variables for Bitbucket Cloud pull requests

NAME VALUE
BITBUCKET_SOURCE_BRANCH source branch
BITBUCKET_TARGET_BRANCH target branch
BITBUCKET_PULL_REQUEST_LINK link
BITBUCKET_PULL_REQUEST_ID id
BITBUCKET_PAYLOAD payload as json string

Environment variables for Bitbucket Cloud pushs

NAME VALUE
REPOSITORY_LINK branch (Deprecated. It will be removed.)
BITBUCKET_SOURCE_BRANCH branch
BITBUCKET_REPOSITORY_URL repository url
BITBUCKET_PAYLOAD payload as json string

Roadmap

  • Build Status propagation, cf. #23
  • Approve Pull Request on successful build, cf. #29
  • Trigger via Pipeline DSL
  • Multi-branch pipelines support
  • Pull requests for Bitbucket Server

Dsl Job snippets

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

Example of pipeline code for building on pull-request create event. It merge from source to target in the PR.

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'

}

bitbucket-push-and-pull-request-plugin's People

Contributors

eiriarte-mendez avatar

Watchers

 avatar  avatar

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.