Skip to content

Commit

Permalink
Introduce REMOTING_OPTS to pass arbitrary options to remoting on st…
Browse files Browse the repository at this point in the history
…artup via an environment variable (#809)

* Introduce REMOTING_OPTS to pass arbitrary options to remoting on startup via an environment variable

* Move REMOTING_OPTS up in the description, deprecate other envvars
  • Loading branch information
Vlatombe authored May 17, 2024
1 parent 040fd59 commit 5c3469a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion jenkins-agent
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# Optional environment variables :
# * JENKINS_JAVA_BIN : Java executable to use instead of the default in PATH or obtained from JAVA_HOME
# * JENKINS_JAVA_OPTS : Java Options to use for the remoting process, otherwise obtained from JAVA_OPTS
# * REMOTING_OPTS : Generic way to pass additional CLI options to agent.jar (see -help)
#
# Deprecated environment variables (prefer setting REMOTING_OPTS)
# * JENKINS_TUNNEL : HOST:PORT for a tunnel to route TCP traffic to jenkins host, when jenkins can't be directly accessed over network
# * JENKINS_URL : alternate jenkins URL
# * JENKINS_SECRET : agent secret, if not set as an argument
Expand Down Expand Up @@ -126,6 +129,6 @@ else
#TODO: Handle the case when the command-line and Environment variable contain different values.
#It is fine it blows up for now since it should lead to an error anyway.

exec $JAVA_BIN $JAVA_OPTIONS -jar /usr/share/jenkins/agent.jar $SECRET $AGENT_NAME $TUNNEL $URL $WORKDIR $WEB_SOCKET $DIRECT $PROTOCOLS $INSTANCE_IDENTITY "$@"
exec $JAVA_BIN $JAVA_OPTIONS -jar /usr/share/jenkins/agent.jar $SECRET $AGENT_NAME $TUNNEL $URL $WORKDIR $WEB_SOCKET $DIRECT $PROTOCOLS $INSTANCE_IDENTITY $REMOTING_OPTS "$@"

fi
11 changes: 10 additions & 1 deletion jenkins-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ Param(
$Protocols = '',
$JenkinsJavaBin = '',
$JavaHome = $env:JAVA_HOME,
$JenkinsJavaOpts = ''
$JenkinsJavaOpts = '',
$RemotingOpts = ''
)

# Usage jenkins-agent.ps1 [options] -Url http://jenkins -Secret [SECRET] -Name [AGENT_NAME]
# Optional environment variables :
# * JENKINS_JAVA_BIN : Java executable to use instead of the default in PATH or obtained from JAVA_HOME
# * JENKINS_JAVA_OPTS : Java Options to use for the remoting process, otherwise obtained from JAVA_OPTS
# * REMOTING_OPTS : Generic way to pass additional CLI options to agent.jar (see -help)
#
# Deprecated environment variables (prefer setting REMOTING_OPTS)
# * JENKINS_TUNNEL : HOST:PORT for a tunnel to route TCP traffic to jenkins host, when jenkins can't be directly accessed over network
# * JENKINS_URL : alternate jenkins URL
# * JENKINS_SECRET : agent secret, if not set as an argument
Expand Down Expand Up @@ -70,6 +74,7 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
'DirectConnection' = 'JENKINS_DIRECT_CONNECTION';
'InstanceIdentity' = 'JENKINS_INSTANCE_IDENTITY';
'Protocols' = 'JENKINS_PROTOCOLS';
'RemotingOpts' = 'REMOTING_OPTS';
}

# this does some trickery to update the variable from the CmdletBinding
Expand Down Expand Up @@ -108,6 +113,10 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
$AgentArguments += @("-secret", $Secret)
$AgentArguments += @("-name", $Name)

if(![System.String]::IsNullOrWhiteSpace($RemotingOpts)) {
$AgentArguments += Invoke-Expression "echo $RemotingOpts"
}

if(![System.String]::IsNullOrWhiteSpace($Tunnel)) {
$AgentArguments += @("-tunnel", "`"$Tunnel`"")
}
Expand Down

0 comments on commit 5c3469a

Please sign in to comment.