我试图从powershell中调用一个resthell方法,从teamcity调用jira。需要正确编码URL才能正常工作。如果我删除这些编码字符,我不会得到正确的结果返回。查看示例和其他来源,jql需要编码。
我的uri是
https://localhost:8443/rest/api/2/search?jql=project%20%3D%20CPS%20and%20fixVersion%20%3D%203.25
然而,每当我在teamcity中输入此内容时,我的构建配置将被提示输入4个新变量。我理解为什么teamcity会这么想,但我已经尝试了一切来逃避它们。
我试过了:
https://localhost:8443/rest/api/2/search?jql=project%%20%%3D%%20CPS%%20and%%20fixVersion%%20%%3D%%203.2
https://localhost:8443/rest/api/2/search?jql=project%%%20%%%3D%%%20CPS%%%20and%%%20fixVersion%%%20%%%3D%%%203.2
https://localhost:8443/rest/api/2/search?jql=project`%20`%3D`%20CPS`%20and`%20fixVersion`%20`%3D`%203.2
我的用法如下:
$jiraFixVersion = $version.Substring(0,$length-5);
$params = @{uri = "https://jira.rtdomau.local:8443/rest/api/2/search?jql=project%20%3D%20CPS%20and%20fixVersion%20%3D%20$($jiraFixVersion)";
Method = 'Get'; #(or POST, or whatever)
Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($user):$($password)"));
} #end headers hash table
} #end $params hash table
$var = invoke-restmethod @params
任何人都可以提出其他建议吗?
答案 0 :(得分:-1)
如果您不使用动态值,请使用单引号作为字符串文字。
$Params = @{ uri = 'https://jira.rtdomau.local:8443/rest/api/2/search?jql=project%20%3D%20CPS%20and%20fixVersion%20%3D%20$($jiraFixVersion)';
...