使用Powershell更改受让人并通过JIRA REST API添加注释以发布问题 [英] Using Powershell to Change Assignee and Add Comment to Issue via JIRA REST API
问题描述
对于看似简单的事情,我没有运气通过REST API更新JIRA问题.
For something so seemingly simple I'm having no luck updating JIRA issues via the REST API.
有人能够使用Powershell更新JIRA问题吗?我已经完全用尽了stackoverflow和atlassian网站上的所有选项.
Has anyone been able to update JIRA issues using Powershell? I've pretty well exhausted all the options on stackoverflow and atlassian's website.
curl,invoke-restmethod或invoke-webrequest脚本没有执行任何操作,但返回了错误.
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.
谢谢!
推荐答案
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."
这篇关于使用Powershell更改受让人并通过JIRA REST API添加注释以发布问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!