The *install-jenkins-agent.ps1* Script =========================== This PowerShell script installs and starts the Jenkins Agent. Parameters ---------- ```powershell /Repos/PowerShell/scripts/install-jenkins-agent.ps1 [[-installDir] ] [[-jenkinsURL] ] [[-secretKey] ] [] -installDir Required? false Position? 1 Default value /opt/jenkins-agent Accept pipeline input? false Aliases Accept wildcard characters? false -jenkinsURL Required? false Position? 2 Default value Accept pipeline input? false Aliases Accept wildcard characters? false -secretKey Required? false Position? 3 Default value Accept pipeline input? false Aliases Accept wildcard characters? false [] This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. ``` Example ------- ```powershell PS> ./install-jenkins-agent.ps1 ``` Notes ----- Author: Markus Fleschutz | License: CC0 Related Links ------------- https://github.com/fleschutz/PowerShell Script Content -------------- ```powershell <# .SYNOPSIS Installs the Jenkins Agent .DESCRIPTION This PowerShell script installs and starts the Jenkins Agent. .EXAMPLE PS> ./install-jenkins-agent.ps1 .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> param([string]$installDir = "/opt/jenkins-agent", [string]$jenkinsURL = "", [string]$secretKey = "") try { "`n⏳ (1/5) Asking for details..." if ($jenkinsURL -eq "") { $jenkinsURL = Read-Host "Enter the URL to the Jenkins controller" } if ($secretKey -eq "") { $secretKey = Read-Host "Enter the secret key" } $stopWatch = [system.diagnostics.stopwatch]::startNew() "`n⏳ (2/5) Installing Java Runtime Environment (JRE)..." & sudo apt install default-jre "`n⏳ (3/5) Creating installation folder at: $installDir ... (if non-existent)" & mkdir $installDir & cd $installDir "`n⏳ (4/5) Downloading Jenkins agent .JAR program from Jenkins controller..." & curl -sO $jenkinsURL/jnlpJars/agent.jar "`n⏳ (5/5) Starting Jenkins agent ..." & nohup java -jar agent.jar -url $jenkinsURL -secret $secretKey -name pi -webSocket -workDir $installDir & [int]$elapsed = $stopWatch.Elapsed.TotalSeconds "✅ Jenkins Agent installed successfully in $($elapsed)s." exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 } ``` *(page generated by convert-ps2md.ps1 as of 06/22/2025 10:37:36)*