Using Powershell to Change Assignee and Add Comment to Issue via JIRA REST API

℡╲_俬逩灬. 提交于 2020-01-05 12:30:11

问题


For something so seemingly simple I'm having no luck updating JIRA issues via the REST API.

Has anyone been able to update JIRA issues using Powershell? I've pretty well exhausted all the options on stackoverflow and atlassian's website.

No scripts for curl, invoke-restmethod or invoke-webrequest have done anything but returned errors.

Retrieving info from the issue is not a problem. Changing it... holy cow.

I'd be immensely grateful if someone could help me find a way to solve this.

Thanks!


回答1:


function ConvertTo-Base64($string) {
    $bytes  = [System.Text.Encoding]::UTF8.GetBytes($string);
    $encoded = [System.Convert]::ToBase64String($bytes);
    return $encoded;
}

function Get-HttpBasicHeader([string]$username, [string]$password, $Headers = @{}) {
    $b64 = ConvertTo-Base64 "$($username):$($Password)"
    $Headers["Authorization"] = "Basic $b64"
    $Headers["X-Atlassian-Token"] = "nocheck"
    return $Headers
}

function add_comment([string]$issueKey,[string]$comment) {
    $body = ('{"body": "'+$comment+'"}')
    $comment=(Invoke-RestMethod -uri ($restapiuri +"issue/$issueKey/comment") -Headers $headers -Method POST -ContentType "application/json" -Body $body).id    
    return $comment
}


$restapiuri = "https://jira.server.com/rest/api/2/"
$headers = Get-HttpBasicHeader "user" "password"

add_comment "MyIssue-1234" "[~test.user] please handle the issue."


来源:https://stackoverflow.com/questions/24422577/using-powershell-to-change-assignee-and-add-comment-to-issue-via-jira-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!