Call Jira REST API for Jira statistics automation

Source: Internet
Author: User

Statistical automation is performed by invoking the Jira Rest Web API, which starts with a login simulation:

$content= @{username= ' user name ';p assword=' Password '}$JSON=$content|convertto-json-Compress$res= Invoke-webrequest-uri"Http://jira Address/rest/auth/1/session"-method Post-body$JSON-contenttype application/JSON$webClient= new-Object Net.webclient#Set encoding style here.$webClient. Encoding=[system.text.encoding]::getencoding ("Utf-8")
<#Note that the response contains the set-Cookie HTTP headers that must is honoured by the caller.IfYou is using a cookie-aware HTTP client then it'll handle all set-Cookie headers automatically. This is important because setting the Jsessionid cookie alone could not be sufficient forThe authentication to work .#>$webClient. Headers.add ("Cookies",$res. headers["Set-cookie"])#write-host "Call Get Login State interface"-foregroundcolor Green#$webClient. Downloadstring ("Http://jira address/rest/auth/1/session")#write-host "Call Exit Login Interface"-foregroundcolor Green#$webClient. Uploadstring ("Http://jira address/rest/auth/1/session", "DELETE", "")#write-host "Call Get Login State interface"-foregroundcolor Green#$webClient. Downloadstring ("Http://jira address/rest/auth/1/session")

Then query all tasks assigned to me and iterate through each task to remove the desired information (for example: Reporter, Developer, frontend, Jira creation time, etc.):

$jiraUri="Jira Address"#query All tasks assigned to cloud-to-outer#search using Search request. Use the JQL statement to find the lookup interface (first to create a JSON object as the body of the post for the lookup)#Create a JSON object in PowerShell.$JSON= @"{    "Jql": "Assign to = outer Cloud",    "StartAt": 0,"MaxResults": +,"Fields": [        "Summary",        "Status",        "Assignee"    ]}"@$apiUri="/rest/api/2/search"$uri=$jiraUri+$apiUri#the header that the Post JSON must add.$webClient. Headers.add ("Content-type","Application/json");$searchResult=$webClient. Uploadstring ($uri,$JSON)#get all the issues (assigned to the outer cloud)$issues= ($searchResult| convertfrom-Json). Issues#judged there was no such fieldfunctionNullornot ($field){    if(($field -ne $null)-and($field -ne ""))    {       $field    }Else{        $field="Displayname:null"    }}#List of people to extractfunctionGetDisplayName ($oName){    $displayNames=$oName|findstr"DisplayName"    if($displayNames. Count-ne1){        foreach($displayName inch $displayNames){            $newDisplayName+=$displayName. Split (":") [1]            $newDisplayName+=" "        }        $newDisplayName    }Else{        $displayNames. Split (":") [1]    }}#Traverse Jira Issueforeach($issue inch $issues){    $apiUri=$jiraUri+"/rest/api/2/issue/"+$issue. Key$issueInfo=$webClient. Downloadstring ($apiUri)    $issueInfo=$issueInfo| convertfrom-Json#$issueInfo. fields    $reporter= GetDisplayName (Nullornot ($issueInfo. Fields.reporter)) Write-host"The person who reported:"$reporter    $productor= GetDisplayName (Nullornot ($issueInfo. fields.customfield_10206)) Write-host"Product Personnel:"$productor    $qianDuan= GetDisplayName (Nullornot ($issueInfo. fields.customfield_10207)) Write-host"Front End:"$qianDuan    $developer= GetDisplayName (Nullornot ($issueInfo. fields.customfield_10208)) Write-host"Development:"$developer    $fenPai= GetDisplayName (Nullornot ($issueInfo. fields.customfield_10002)) Write-host"Assign to:"$fenPai    $tiCeTime=$issueInfo. fields.created Write-host"time to test:"$tiCeTimeWrite-host"use case data:"$issueInfo. fields.customfield_11402$issueInfo. fields.customfield_10400 Write-host"Number of Bugs:"$issueInfo. fields.customfield_10202 Read-Host}

Call Jira REST API for Jira statistics automation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.