Created
May 29, 2018 13:32
-
-
Save mwallner/536c88b142cb69cfb56f9e2593c484f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$API_User = "user" | |
$API_Pass = "password" | |
$API_URL = "http://jenkins-host" | |
$API_Port = "8082" | |
$API_NODE= "node-name" | |
$API_MESSAGE= "bye!" | |
$CRUMB_URI = "${API_URL}:${API_Port}/jenkins/crumbIssuer/api/json" | |
Write-Host "getting crumb from '$CRUMB_URI'" | |
$h = @{} | |
$h.Add('Authorization', 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$(${API_User}):$(${API_Pass})"))) | |
$Params = @{uri = $CRUMB_URI; | |
Method = 'Get'; | |
Headers = $h;} | |
$API_Crumb = Invoke-RestMethod @Params | |
$h.Add('Jenkins-Crumb', $API_Crumb.crumb) | |
$Params['uri'] = "${API_URL}:${API_Port}/jenkins/computer/${API_NODE}/toggleOffline?offlineMessage=${API_MESSAGE}" | |
$Params['Method'] = 'Post' | |
$Params['Headers'] = $h | |
Invoke-RestMethod @Params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment