Last active
August 5, 2024 23:38
-
-
Save Badgerati/f70cef2fc42b7ba6ce79 to your computer and use it in GitHub Desktop.
PowerShell wrapper around the inbuilt Jenkins CLI
This file contains 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
######################################################## | |
# Author: Matthew Kelly (Badgerati) | |
# | |
# This is a PowerShell wrapper around the inbuilt Jenkins CLI. | |
# It simplifies the calls to Jenkins, by just allowing you | |
# to call commands with a simple "jenkins" call. | |
# | |
# Best used with the path to the script in your PATH. | |
# | |
# Requirements: | |
# jenkins-cli.jar | |
# | |
# Setup: | |
# Before running this script, assign the location of your | |
# jenkins-cli.jar file, and the endpoint to your Jenkins | |
# website into the first two variables. | |
# | |
# Usage: | |
# > jenkins <command> <arguments> | |
# | |
# Examples: | |
# > jenkins login --username <username> --password <password> | |
# > jenkins build "Test Website" | |
# > jenkins list-jobs QA | |
######################################################## | |
$jarLocation = 'C:\Projects\JenkinsCLI\jenkins-cli.jar' | |
$endpoint = 'http://jenkins:8080/' | |
$command = $args[0] | |
if ($command -eq $null -or [string]::IsNullOrEmpty($command.Trim())) { | |
Write-Host 'No command supplied' -ForegroundColor Red | |
return | |
} | |
$call = "java -jar $jarLocation -s $endpoint $command" | |
$count = $args.Length | |
for ($i = 1; $i -lt $count; $i++) { | |
$call = $call + ' "' + $args[$i] + '"' | |
} | |
cmd /C $call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment