Issue with my powershell script aimed to kick off a jenkins job

49 Views Asked by At
$UserName = "user"
$Password = "password"
$API_URL = "https://jenkinsservername"
$JobName = "firstjob"
$JobToken = "generatedtoken"
$header = @{}
$header.Add('Authorization', 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$(${UserName}):$(${Password})")))
$Params = @{uri = "${API_URL}/crumbIssuer/api/json";
        Method = 'Get';
        Headers = $header;}
$API_Crumb = Invoke-RestMethod @Params
write-host $API_Crumb
$h.Add('Jenkins-Crumb', $API_Crumb.crumb)
$Params['uri'] = "https://jenkinsservername/$JobName/build?token=$JobToken"
$Params['Method'] = 'Post'
$Params['Headers'] = $header
Invoke-RestMethod @Params

Invoke-RestMethod : The remote name could not be resolved: 'https' At C:\path\to\script.ps1:12 char:14

  • $API_Crumb = Invoke-RestMethod @Params1

  •          ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    Invoke-RestMethod : Object reference not set to an instance of an object. At C:\path\to\script.ps1:19 char:1

    • Invoke-RestMethod @Params2 -WebSession $Session
    •   + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], NullReferenceException
        + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
      
      

You contributions will be appreciated

0

There are 0 best solutions below