Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate Jira Service Management Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Jira Service Management data from PowerShell? This article demonstrates how to utilize the Jira Service Management Cmdlets for tasks like connecting to Jira Service Management data, automating operations, downloading data, and more.
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.
PowerShell Cmdlets or ADO.NET Provider?
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.
Connecting with a Cloud Account
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:
- User: Set this to the username of the authenticating user.
- APIToken: Set this to the API token found previously.
Connecting with a Service Account
To authenticate with a service account, you will need to supply the following connection properties:
- User: Set this to the username of the authenticating user.
- Password: Set this to the password of the authenticating user.
- URL: Set this to the URL associated with your JIRA Service Desk endpoint. For example, https://yoursitename.atlassian.net.
Note: Password has been deprecated for connecting to a Cloud Account and is now used only to connect to a Server Instance.
Accessing Custom Fields
By default, the connector only surfaces system fields. To access the custom fields for Issues, set IncludeCustomFields.
PowerShell
-
Install the module:
Install-Module JiraServiceDeskCmdlets
-
Connect:
$jiraservicedesk = Connect-JiraServiceDesk -ApiKey "$ApiKey" -User "$User"
-
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'}
ADO.NET
-
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 Jira Service Management Data
PowerShell
Update-JiraServiceDesk -Connection $JiraServiceDesk -Columns @('RequestId','ReporterName') -Values @('MyRequestId', 'MyReporterName') -Table Requests -Id "MyId"
ADO.NET
$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()
Insert Jira Service Management Data
PowerShell
Add-JiraServiceDesk -Connection $JiraServiceDesk -Table Requests -Columns @("RequestId", "ReporterName") -Values @("MyRequestId", "MyReporterName")
ADO.NET
$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()
Delete Jira Service Management Data
PowerShell
Remove-JiraServiceDesk -Connection $JiraServiceDesk -Table "Requests" -Id "MyId"
ADO.NET
$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