I want to execute a transition in JIRA via Jenkins. The Jira Issue Updater is bugged with the affects version so I tried a curl.
This worked out very well:
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
But now I have to run this with powershell on a windows server.
Anyone know a workaround for this usecase or how to do that with an Invoke-WebRequest?
Have you used the cmdlets from https://atlassianps.org/ I've had a great deal of success with them. In fact there is an Invoke-JiraIssueTransition that looks like it would do what you might need.
found this script: Using Powershell to Change Assignee and Add Comment to Issue via JIRA REST API
and modified it a little:
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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.