我有一个Jenkins职位,其中“ Trigger Builds Remotely”处于打开状态,并且我有身份验证令牌。
我有这些powershell脚本,我想在其中远程触发构建:
$headersForRequest = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headersForRequest.Add("Accept","*/*")
$headersForRequest.Add("accept-encoding","gzip, deflate")
$headersForRequest.Add("Jenkins-Crumb","crumbXXXXXXX")
$JenkinsURL = "XXX.XX.XXX.XXX:8080"
$userName = "QAA_Jenkins_API"
$Auth = "xAfsgAAXsdfdsfs"
$JobName = "Run - Powershell script"
$JobToken = "34353fgdfgd"
$FullURL = "$JenkinsURL/job/$JobName/build?token=$JobToken"
Invoke-RestMethod -UseBasicParsing $FullURL -Method Post -ContentType "application/json" -Headers $headersForRequest
问题: 当我执行此Powershell脚本时,出现错误:
Invoke-RestMethod :
Error 403 No valid crumb was included in the request
HTTP ERROR 403
Problem accessing /job/Run%20-%20Powershell%20script/build. Reason:
No valid crumb was included in the requestPowered by Jetty:// 9.4.z-SNAPSHOT
At C:\Users\ME\Documents\TUTS\RESTApi-Calls-PShell\Jenkins API.ps1:13 char:1
+ Invoke-RestMethod -UseBasicParsing $FullURL -Method Post -ContentType ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMeth
od], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodC
ommand
有什么想法吗?