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
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 -Name PS.BitBucket
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-BitBucketServer -Url "http://example:7990"
Set-BitBucketCredential -Credential admin
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-BitBucketProjects
Get-BitBucketRepoByProject -Project "TES"
Get-BitBucketAllRepo
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]"
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
- Do while creating a new repo
New-BitBucketRepo -Project "TES" -Repository "ABC" -WithGitFlowBranch -SetBranchPermission -BranchPermissionJson "C:\BranchPer.json"
- 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-BitBucketRepoSizeByProject -Project "TES"
Get-BitBucketAllRepoSize
New-CreateBranch -Project "TES" -Repository "TEST1" -SourceBranch "refs/heads/develop" -NewBranch "release/1.0"
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.
Created and maintained by Shankar.
Apache License, Version 2.0 (see LICENSE)