10

Using Jira REST API with PowerShell

 3 years ago
source link: https://zoph.me/posts/2017-01-05-using-jira-api-with-powershell/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Jan 3, 2017

Using Jira REST API with PowerShell

For automation purposes, I needed a tool to interact with the REST API of Atlassian Jira over Powershell commands.

I found a great module developed by replicaJunction and contributors on Github called PSJira.

Installation

You will need

First-Run

Set-JiraConfigServer -Server 'https://my.jira.server.com:port'

Setup jira credentials in .ps1

Encrypt credentials (Once)

Do this with the Windows session of the user who will launch the .ps1 scripts (service account)

$passwd = ConvertTo-SecureString “PlainTextPassword” -AsPlainText -Force
$encrypted = ConvertFrom-SecureString -secureString $passwd
$encrypted | Set-Content c:\path\cred.txt

In your .ps1 script

Load credential, and launch a connection to Jira.

$secure = Get-Content 'C:\path\cred.txt' | convertto-securestring
$cred = New-Object System.Management.Automation.PSCredential ("Jira User", $secure)
New-JiraSession -Credential $cred

Basics commands

Get-JiraIssue #-Query -Filter -Key
Add-JiraIssueComment TEXT -VisibleRole 'All Users'
Set-JiraIssue #-Assignee
New-JiraIssue #-Project PROJECT_NAME -IssueType Bug -Priority 1 -Summary 'Test from PSJira' -Description 'Content of your Bug Issue'
``

#### Examples

In my case, we created a bot called [Lucy](http://www.imdb.com/title/tt2872732/) who launch tidies tasks on our Jira instance (scheduled with RES Automation Manager), she can update idle tickets for example, or automatically assign tickets to Administrators based on Jira filters, etc..

I used PowerShell's `Get-Random` function to render her speech more 'Human', she takes a random sentence on a simple txt file.

```powershell
$random = Get-Content 'C:\path\Speak.txt' | Get-Random
Get-JiraIssue -Filter YOU_FILTER_ID | Add-JiraIssueComment $random -VisibleRole 'All Users'

Automation, Automation, Automation.

That’s all folks!

zoph.


jirapowershellapirestautomationdevops

244 Words

2017-01-03 20:31 +0000


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK