Using Powershell to Change Assignee and Add Commen

2019-07-26 14:33发布

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条回答
别忘想泡老子
2楼-- · 2019-07-26 14:48
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."
查看更多
登录 后发表回答