My PowerShell script:
$Params = @{
uri = \"http://${API_URL}:${API_Port}/crumbIssuer/api/json\";
Method = \'Get\';
Headers = @{
Auth
I modified the code as follows and it worked. Not sure though why previous code was throwing error.
$API_User = "admin"
$API_Pass = "password"
$API_URL = "localhost"
$API_Port = "8080"
$API_Job = "test01"
$h = @{}
$h.Add('Authorization', 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$(${API_User}):$(${API_Pass})")))
$Params = @{uri = "http://${API_URL}:${API_Port}/crumbIssuer/api/json";
Method = 'Get';
Headers = $h;}
$API_Crumb = Invoke-RestMethod @Params
$h.Add('Jenkins-Crumb', $API_Crumb.crumb)
$Params['uri'] = "http://${API_URL}:${API_Port}/job/${API_Job}/build"
$Params['Method'] = 'Post'
$Params['Headers'] = $h
Invoke-RestMethod @Params