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] <String>] [[-jenkinsURL] <String>] [[-secretKey] <String>] [<CommonParameters>]

-installDir <String>
    
    Required?                    false
    Position?                    1
    Default value                /opt/jenkins-agent
    Accept pipeline input?       false
    Accept wildcard characters?  false

-jenkinsURL <String>
    
    Required?                    false
    Position?                    2
    Default value                http://tux:8080
    Accept pipeline input?       false
    Accept wildcard characters?  false

-secretKey <String>
    
    Required?                    false
    Position?                    3
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

[<CommonParameters>]
    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 = "http://tux:8080", [string]$secretKey = "")

try {
	"`n⏳ (1/4) Installing Java Runtime Environment (JRE)..."
	& sudo apt install default-jre

	"`n⏳ (2/4) Creating installation folder at: $installDir ... (if non-existent)"
	& mkdir $installDir
	& cd $installDir

	"`n⏳ (3/4) Loading current .JAR program from Jenkins controller..."
	& curl -sO $jenkinsURL/jnlpJars/agent.jar

	"`n⏳ (4/4) Starting Jenkins agent ..."
	& java -jar agent.jar -url $jenkinsURL -secret $secretKey -name pi -webSocket -workDir $installDir

	exit 0 # success
} catch {
        "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
        exit 1
}
```

*(page generated by convert-ps2md.ps1 as of 01/23/2025 12:15:21)*
