0

I am trying to invoke a rest method in powershell to jira from teamcity. The URL needs to be correctly encoded to work correctly. If I remove these encoded characters I do not get the correct result returned. Looking at examples and otehr sources the jql requires the encoded as such.

my uri is

https://localhost:8443/rest/api/2/search?jql=project%20%3D%20CPS%20and%20fixVersion%20%3D%203.25

however everytime I enter this in teamcity my build config is prompted for 4 new variables. I understand why teamcity thinks this but I have tried everything to escape them.

I have tried:

  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

my usage is below:

$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

Can anyone suggestion anything else ?

Dritzz
  • 159
  • 1
  • 1
  • 10
  • A duplicate of https://stackoverflow.com/q/4389946/606728? – cyberskunk Jul 29 '17 at 10:08
  • Doubling or tripling the % signs should do it. (I never know when to double and triple, but one or the other tends to work.) When you tried that, what error did you get? Was it different than without the doubling/tripling? (OTOH, I don't think escaping with `\`` would do anything reasonable here.) – sferencik Jul 31 '17 at 04:44

1 Answers1

-1

If you're not using dynamic values, use single-quotes for a string literal.

$Params = @{ uri = 'https://jira.rtdomau.local:8443/rest/api/2/search?jql=project%20%3D%20CPS%20and%20fixVersion%20%3D%20$($jiraFixVersion)';
...
Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
  • This seems irrelevant. @Dritzz *is* using "dynamic values" (variables); see `$jiraFixVersion`. Moreover, his problem is with %, not $. – sferencik Jul 31 '17 at 04:41