Skip to content

Commit

Permalink
Allows to pass JAVA_OPTS to the JVM
Browse files Browse the repository at this point in the history
Just like the linux version
  • Loading branch information
Vlatombe committed May 24, 2021
1 parent f96251f commit 6d66b7d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions jenkins-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Param(
$DirectConnection = '',
$InstanceIdentity = '',
$Protocols = '',
$JavaHome = $env:JAVA_HOME
$JavaHome = $env:JAVA_HOME,
$JavaOpts = ''
)

# Usage jenkins-agent.ps1 [options] -Url http://jenkins -Secret [SECRET] -Name [AGENT_NAME]
Expand All @@ -53,9 +54,8 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
# if `docker run` only has one argument, we assume user is running alternate command like `powershell` or `pwsh` to inspect the image
Invoke-Expression "$Cmd"
} else {
$AgentArguments = @("-cp", "C:/ProgramData/Jenkins/agent.jar", "hudson.remoting.jnlp.Main", "-headless")

# this maps the variable name from th CmdletBinding to environment variables
# this maps the variable name from the CmdletBinding to environment variables
$ParamMap = @{
'Tunnel' = 'JENKINS_TUNNEL';
'Url' = 'JENKINS_URL';
Expand All @@ -66,6 +66,7 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
'DirectConnection' = 'JENKINS_DIRECT_CONNECTION';
'InstanceIdentity' = 'JENKINS_INSTANCE_IDENTITY';
'Protocols' = 'JENKINS_PROTOCOLS';
'JavaOpts' = 'JAVA_OPTS';
}

# this does some trickery to update the variable from the CmdletBinding
Expand All @@ -89,6 +90,14 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
}
}

$AgentArguments = @()

if(![System.String]::IsNullOrWhiteSpace($JavaOpts)) {
$AgentArguments += @($JavaOpts.split(" "))
}

$AgentArguments += @("-cp", "C:/ProgramData/Jenkins/agent.jar", "hudson.remoting.jnlp.Main", "-headless")

if(![System.String]::IsNullOrWhiteSpace($Tunnel)) {
$AgentArguments += @("-tunnel", "`"$Tunnel`"")
}
Expand All @@ -114,7 +123,7 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
if(![System.String]::IsNullOrWhiteSpace($InstanceIdentity)) {
$AgentArguments += @('-instanceIdentity', $InstanceIdentity)
}

if(![System.String]::IsNullOrWhiteSpace($Protocols)) {
$AgentArguments += @('-protocols', $Protocols)
}
Expand Down

0 comments on commit 6d66b7d

Please sign in to comment.