Skip to content

Instantly share code, notes, and snippets.

@Badgerati
Last active April 8, 2021 19:43
Show Gist options
  • Save Badgerati/f70cef2fc42b7ba6ce79 to your computer and use it in GitHub Desktop.
Save Badgerati/f70cef2fc42b7ba6ce79 to your computer and use it in GitHub Desktop.
PowerShell wrapper around the inbuilt Jenkins CLI
########################################################
# 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