Linux Bash:
Wroking: ***
curl -u "Account:PWD or API Token" 'http://FQDN:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
Return:
Jenkins-Crumb:***************************
curl -X POST -u "Account:PWD or API Token" -H "Jenkins-Crumb:***************************" http://FQDN:8080/view/Operation/view/2_Stage/job/****/buildWithParameters?token=****&cause=trigger+by+shavlik+POC
PowerShell:
Start-Sleep -s 180
$JenkinsURL = "http://FQDN:8080"
$JobName = "view/Operation/view/2_Stage/job/****"
$JobToken = "****************t"
$Auth = "Account:PWD or API Token"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Auth)
$Base64bytes = [System.Convert]::ToBase64String($Bytes)
$Headers = @{ "Authorization" = "Basic $Base64bytes"}
$CrumbIssuer = "$JenkinsURL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,`":`",//crumb)"
$Crumb = Invoke-WebRequest -UseBasicParsing $CrumbIssuer -Headers $Headers
Write-Host $Crumb
$Regex = '^Jenkins-Crumb:([A-Z0-9]*)'
$Matches = @([regex]::matches($crumb, $regex, 'IgnoreCase'))
$RegCrumb = $Matches.Groups[1].Value
$Headers.Add("Jenkins-Crumb", "$RegCrumb")
Write-Host $Headers
$FullURL = "$JenkinsURL/$JobName/buildWithParameters?token=$JobToken"
Write-Host $FullURL
Invoke-WebRequest -UseBasicParsing $FullURL -Method POST -Headers $Headers
<End>
Refer:
Enable the URL job trigger:
https://www.nczonline.net/blog/2015/10/triggering-jenkins-builds-by-url/
CSRF Protection Explained
https://support.cloudbees.com/hc/en-us/articles/219257077-CSRF-Protection-Explained
Trigger Jenkins Builds Using PowerShell
https://www.smartfile.com/blog/trigger-jenkins-builds-using-powershell/
PowerShell Command
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/start-sleep?view=powershell-6