通过powershell的JIRA API

时间:2018-02-28 14:23:47

标签: powershell jenkins jira

我想通过Jenkins在JIRA中执行转换。 Jira Issue Updater会受到影响版本的影响,所以我尝试了一个卷曲。

这很好用:

curl -D- -u user:pw -X POST --data {\"transition\":{\"id\":\"71\"}} -H "Content-Type: application/json" https://jira.com/rest/api/2/issue/ID/transitions?expand=transitions.fields

但现在我必须在Windows服务器上使用PowerShell运行它。

任何人都知道此用例的解决方法或如何使用Invoke-WebRequest执行此操作?

2 个答案:

答案 0 :(得分:0)

您是否使用了https://atlassianps.org/中的cmdlet我已经取得了很大的成功。实际上有一个Invoke-JiraIssueTransition看起来像你可能需要的那样。

答案 1 :(得分:0)

找到了这个脚本:Using Powershell to Change Assignee and Add Comment to Issue via JIRA REST API

并对其进行了一些修改:

    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
}

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


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

add_comment "ticket-id" "comment"
transition "ticket-id" "transitionid"