Skip to end of metadata
Go to start of metadata

Plugin Information

View Bitbucket OAuth on the plugin site for more information.

This Jenkins plugin enables OAuth authentication for Bitbucket users.

Setup

First you need to get consumer key/secret from Bitbucket.

  1. Log into your Bitbucket account.
  2. Click on your account avatar in the top right corner and select Bitbucket Settings.
  3. If your are a member of an organization, ensure you are on Team settings, not Account settings, from the drop down.
  4. Under ACCESS MANAGEMENT select OAuth.
  5. Under OAuth consumers, click Add consumer.
  6. The system requests the following information: Name is required. Others are optional.
  7. Under Permissions, select Account > Read and Team membership > Read(optional).
  8. Click Save. The system generates a key and a secret for you. Toggle the consumer name to see the generated Key and Secret value for your consumer.

Second, you need to configure your Jenkins.

  1. Open Jenkins Configure System page.
  2. Set correct URL to Jenkins URL.
  3. Click Save button.
  4. Open Jenkins Configure Global Security page.
  5. Check Enable security.
  6. Select Bitbucket OAuth Plugin in Security Realm.
  7. Input your Consumer Key to Client ID.
  8. Input your Consumer Secret to Client Secret.
  9. Click Save button.

Bitbucket Team access Support

Based on the teams that user has access to, this plugin automatically creates groups of the form

team::role

Supported roles are admin, contributor and member

Examples

  • team1::admin
  • team2::contributor
  • team3::member

These group names can be used in Jenkins Matrix-based security to give fine grained access control based on the users team access in Bitbucket.

Configure plugin via Groovy script

Either automatically upon Jenkins post-initialization or through Jenkins script console, example:

import hudson.security.AuthorizationStrategy
import hudson.security.SecurityRealm
import jenkins.model.Jenkins
import org.jenkinsci.plugins.BitbucketSecurityRealm

// parameters
def bitbucketSecurityRealmParameters = [
  clientID:     '012345678901234567',
  clientSecret: '012345678901234567012345678901'
]

// security realm configuration
SecurityRealm bitbucketSecurityRealm = new BitbucketSecurityRealm(
  bitbucketSecurityRealmParameters.clientID,
  bitbucketSecurityRealmParameters.clientSecret
)

// authorization strategy - full control when logged in
AuthorizationStrategy authorizationStrategy = new hudson.security.FullControlOnceLoggedInAuthorizationStrategy()

// authorization strategy - set anonymous read to false
authorizationStrategy.setAllowAnonymousRead(false)

// get Jenkins instance
Jenkins jenkins = Jenkins.getInstance()

// add configurations to Jenkins
jenkins.setSecurityRealm(bitbucketSecurityRealm)
jenkins.setAuthorizationStrategy(authorizationStrategy)

// save current Jenkins state to disk
jenkins.save()

Version History

Version 0.7 (1 May, 2018)

  • Fixed Groovy example did not work

Version 0.6 (25 Feb, 2018)

  • Added Bitbucket API 2.0 support (Pluign requires Account Read Permission only)
  • Added spport for adding user authorities based on bitbucket team/role (related: Pull Request #11)

Version 0.5 (5 Jun, 2016)

Version 0.4 (14 May, 2014)

Version 0.3 (31 Jul, 2013)

  • Works on reverse proxy environments ( Use Jenkins URL configuration instead of request URL )

Version 0.1 (29 May, 2013)

  • Initial release

7 Comments

  1. I do not see Bitbucket OAuth Plugin in Security Realm in my Jenkins Console. I only see :-

    Delegate to servlet container    
    Google Apps SSO (with OpenID)    
     Jenkins's own user database    
     LDAP
     OpenID SSO    
     Unix user/group database

    what do I need to do about it?

    

  2. Please send me the link for the installer of "Bitbucket OAuth Plugin"

  3. You can find it on Manage Jenkins > Manage Plugins > Available > Bitbucket OAuth Plugin.

    Check Bitbucket OAuth Plugin and click the install button.

  4. Hello!

    I installed the plugin and I see it in my security settings.

    My question is: I have a lot of projects that use SVN or other system, so my jenkins (which is internal) is not secured. Can I use this plugin per project instead of all my jenkins configuration?

    Thanks in advance.

  5. I have followed the steps to get consumer key/secret and configure jenkins security. What do I do afterwards to create a new build? I am new to jenkins and need to make it so every time a git push happens in bitbucket a build is started by jenkins. Clear defined steps on how to make a build would be most helpful.

    thanks in advance

  6. I've just published a Groovy script to configure this plugin;

    https://gist.github.com/ivan-pinatti/87b19e40f9b22fa3b9fa04194bdf176c

     

    Also just did a pull request to add it to the official README page;

    https://github.com/jenkinsci/bitbucket-oauth-plugin/pull/2

  7. Hi All.

    How can I use Bitbucket OAuth and AD together?

    In the global security (Jenkis) activation for Bitbucket OAuth means automatically deactivation for AD. I want to test OAuth for Bitbucket/Jira but I must have AD.

    Is it impossible to use both?

    Thanks in advance

    Volker