Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Set-ExecutionPolicy Unrestricted
# Jenkins plugin will dynamically pass the server name and vm name.
# If your jenkins server is configured for security , make sure to edit command for how slave executes
# You may need to pass credentails or secret in the command , Refer to help by running "java -jar slave.jar --help"
$jenkinsserverurl = $args[0]
$vmname = $args[1]
# Download the file to a specific location
Write-Output "Downloading zulu SDK "
$source = ""
mkdir c:\azurecsdir
$destination = "c:\azurecsdir\"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($source, $destination)
Write-Output "Unzipping JDK "
# Unzip the file to specified location
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($destination)
mkdir c:\java
$destination = $shell_app.namespace("c:\java")
Write-Output "Successfully downloaded and extracted JDK "
# Downloading jenkins slaves jar
Write-Output "Downloading jenkins slave jar "
$slaveSource = $jenkinsserverurl + "jnlpJars/slave.jar"
$destSource = "c:\java\slave.jar"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($slaveSource, $destSource)
# execute slave
Write-Output "Executing slave process "
$serverURL=$jenkinsserverurl+"computer/" + $vmname + "/slave-agent.jnlp"
# syntax for credentials username:apitoken or username:password
# you can get api token by clicking on your username --> configure --> show api token
& $java $jar $destSource $jnlpCredentialsFlag $credentails $jnlpUrl $serverURL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment