![]() |
VOOZH | about |
The CData Cmdlets for Jira Service Management are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Jira Service Management.
The Cmdlets are not only a PowerShell interface to Jira Service Management, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Jira Service Management data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Jira Service Management. To access Jira Service Management data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Jira Service Management.
Once you have acquired the necessary connection properties, accessing Jira Service Management data in PowerShell can be enabled in three steps.
You can establish a connection to any Jira Service Desk Cloud account or Server instance.
To connect to a Cloud account, you'll first need to retrieve an APIToken. To generate one, log in to your Atlassian account and navigate to API tokens > Create API token. The generated token will be displayed.
Supply the following to connect to data:
To authenticate with a service account, supply the following connection properties:
Note: Password has been deprecated for connecting to a Cloud Account and is now used only to connect to a Server Instance.
By default, the connector only surfaces system fields. To access the custom fields for Issues, set IncludeCustomFields.
Install the module:
Install-Module JiraServiceDeskCmdlets
Connect:
$jiraservicedesk = Connect-JiraServiceDesk -ApiKey "$ApiKey" -User "$User" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$currentstatus = "Open" $requests = Select-JiraServiceDesk -Connection $jiraservicedesk -Table "Requests" -Where "CurrentStatus = `'$CurrentStatus`'" $requests
You can also use the Invoke-JiraServiceDesk cmdlet to execute SQL commands:
$requests = Invoke-JiraServiceDesk -Connection $jiraservicedesk -Query 'SELECT * FROM Requests WHERE CurrentStatus = @CurrentStatus' -Params @{'@CurrentStatus'='Open'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Jira Service Management\lib\System.Data.CData.JiraServiceDesk.dll")
Connect to Jira Service Management:
$conn= New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskConnection("ApiKey=myApiKey;User=MyUser;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the JiraServiceDeskDataAdapter, execute an SQL query, and output the results:
$sql="SELECT RequestId, ReporterName from Requests"
$da= New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.requestid $_.reportername
}
Update-JiraServiceDesk -Connection $JiraServiceDesk -Columns @('RequestId','ReporterName') -Values @('MyRequestId', 'MyReporterName') -Table Requests -Id "MyId"
$cmd = New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskCommand("UPDATE Requests SET CurrentStatus='Open' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-JiraServiceDesk -Connection $JiraServiceDesk -Table Requests -Columns @("RequestId", "ReporterName") -Values @("MyRequestId", "MyReporterName")
$cmd = New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskCommand("INSERT INTO Requests (CurrentStatus) VALUES (@myCurrentStatus)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskParameter("@myCurrentStatus","Open")))
$cmd.ExecuteNonQuery()
Remove-JiraServiceDesk -Connection $JiraServiceDesk -Table "Requests" -Id "MyId"
$cmd = New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskCommand("DELETE FROM Requests WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Jira Service Management Data Provider to get started:
Download NowLearn more:
👁 Jira Service Management IconRapidly create and deploy powerful .NET applications that integrate with Jira Service Management.