![]() |
VOOZH | about |
The CData Cmdlets Module for Bitbucket is a standard PowerShell module offering straightforward integration with Bitbucket. Below, you will find examples of using our Bitbucket Cmdlets with native PowerShell cmdlets.
For most queries, you must set the Workspace. The only exception to this is the Workspaces table, which does not require this property to be set, as querying it provides a list of workspace slugs that can be used to set Workspace. To query this table, you must set Schema to 'Information' and execute the query SELECT * FROM Workspaces>.
Setting Schema to 'Information' displays general information. To connect to Bitbucket, set these parameters:
Bitbucket supports OAuth authentication only. To enable this authentication from all OAuth flows, you must create a custom OAuth application, and set AuthScheme to OAuth.
Be sure to review the Help documentation for the required connection properties for you specific authentication needs (desktop applications, web applications, and headless machines).
From your Bitbucket account:
$conn = Connect-Bitbucket -Workspace "$Workspace" -Schema "$Schema" -InitiateOAuth "$InitiateOAuth"
Follow the steps below to retrieve data from the Issues table and pipe the result into to a CSV file:
Select-Bitbucket -Connection $conn -Table Issues | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myIssuesData.csv -NoTypeInformation
You will notice that we piped the results from Select-Bitbucket into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.
The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.The following line deletes any records that match the criteria:
Select-Bitbucket -Connection $conn -Table Issues -Where "Id = 1" | Remove-Bitbucket
The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Bitbucket, checking first whether a record already exists and needs to be updated instead of inserted.
Import-Csv -Path C:\MyIssuesUpdates.csv | %{
$record = Select-Bitbucket -Connection $Bitbucket -Table Issues -Where ("Id = `'"+$_.Id+"`'")
if($record){
Update-Bitbucket -Connection $bitbucket -Table Issues -Columns ("Title","ContentRaw") -Values ($_.Title, $_.ContentRaw) -Where ("Id = `'"+$_.Id+"`'")
}else{
Add-Bitbucket -Connection $bitbucket -Table Issues -Columns ("Title","ContentRaw") -Values ($_.Title, $_.ContentRaw)
}
}
As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!
Download a free trial of the Bitbucket Cmdlets to get started:
Download NowLearn more:
👁 Bitbucket IconAn easy-to-use set of PowerShell Cmdlets offering real-time access to Bitbucket. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.