Skip to content

i9shankar/ps-bitbucket

Repository files navigation

Powershell BitBucket module

PS.BitBucket is a PowerShell module that provides cmdlets to intract with BitBucket instance. It uses most of the REST API reference availabe here REST API and few from other places like Branch permission.

This allows fast access to BitBucket UI functions in automated way.

The module handles only authenticated method, it supports multiple funcationlity of BitBucket in group manner (useful for Administrator to GET stats), Here are few example (Detailed below) supported: :Project, Repo, Branch, BranchPermission, Size, ListOfRepos, CreateRepo, CreateBranch, CurrentVersion

Getting Started

PS.BitBucket is available on PowerShell Gallery , You can install package if you have PowerShellGet installed already, otherwise you can follow the instruction to install from PowerShell Gallery here https://www.powershellgallery.com/.

Install module

Install-Module -Name PS.BitBucket

To start with

Set BitBucket server URL and login Credentails, This will be used for all the command you run. In most cases, to get full information, its good to have admininstrator level access.

Set server URL

Set-BitBucketServer -Url "http://example:7990"

Set Credential

Set-BitBucketCredential -Credential admin

Verify

Get-BitBucketServer
Get-BitBucketInfo

Note: All these command output depends on permission you have. Any information are shown by these cmdlets are similar to what you see on UI.

Get all projects

Get-BitBucketProjects

Get all Repositories under given Project ID

Get-BitBucketRepoByProject -Project "TES"

Get all repository hosted on Bitbucket

Get-BitBucketAllRepo

Create a new empty repository

New-BitBucketRepo -Project "TES" -Repository "ABC"

(There are mutliple optional param available for New-BitBucketRepo, All of these works if pass with -WithGitFlowBranch)

Set the user full name and email (This required in order to get user real name when pushing new branches)

Set-UserFullNameAndEmail -FullName "admin" -EmailId "[email protected]"

Create a new repository with gitflow branch (develop/master)

New-BitBucketRepo -Project "TES" -Repository "ABC" -WithGitFlowBranch

Note: Above command also looks for a .gitignore file under C:\Git\ folder.

Create a new repository with gitflow branch and set develop as default branch (Git push marks master as default)

New-BitBucketRepo -Project "TES" -Repository "ABC" -WithGitFlowBranch -SetDefaultBranch

You can also change default branch at later stage as

Set-DefaultBranch -Project "TES" -Repository "ABC" -Branch "develop"

Create a new repository with gitflow branch, Set branch permission as attached Screenshot

New-BitBucketRepo -Project "TES" -Repository "ABC" -WithGitFlowBranch -SetBranchPermission

Note: I have added a standard branch permission, every org has different set of branch permission, to use your own org standard branch permission, write a file similar to public\BranchPermission.json. There are two ways to set custom branch permission

  1. Do while creating a new repo
New-BitBucketRepo -Project "TES" -Repository "ABC" -WithGitFlowBranch -SetBranchPermission -BranchPermissionJson "C:\BranchPer.json"
  1. Change at later stage for existing repo
Set-BranchPermission -Project "TES" -Repository "ABC" --BranchPermissionJson "C:\BranchPer.json"

OR to set branch permission as defined in this module for existing repo:

Set-BranchPermission -Project "TES" -Repository "ABC"

Below cmdlet will help to get size for repositories under given projects or all the repository hosted on BitBucket. These are requred sometime for audit purpose. (Limitation: These command will break if a repository name has space, I am still working on it)

Get all repository Approximate size (in KBs) for given Projects

Get-BitBucketRepoSizeByProject -Project "TES"

Get all repository Approximate size (in KBs)

Get-BitBucketAllRepoSize

Create new branch

New-CreateBranch -Project "TES" -Repository "TEST1" -SourceBranch "refs/heads/develop" -NewBranch "release/1.0"

Disclaimer/Issues

This is an open source project which is NOT supported by the BitBucket team. All questions/bugs about this module should be entered on this github project or feel free to contribute to this project if you have a possible fix for it. Feel free to request for new feature/cmdlet. Your suggestion/request will help shape up the module according to needs of the community. All these current implementation are based on my experience with BitBucket day to day usage.

Authors

Created and maintained by Shankar.

License

Apache License, Version 2.0 (see LICENSE)

About

PowerShell module to interact with Atlassian Bitbucket

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published