Skip to content

Commit

Permalink
Add -noReconnectAfter option support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe committed May 7, 2024
1 parent a37e97a commit 611dc9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion jenkins-agent
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# * JENKINS_INSTANCE_IDENTITY: The base64 encoded InstanceIdentity byte array of the Jenkins controller. When this is set,
# the agent skips connecting to an HTTP(S) port for connection info.
# * JENKINS_PROTOCOLS: Specify the remoting protocols to attempt when instanceIdentity is provided.
# * JENKINS_NO_RECONNECT_AFTER: Do not attempt to reconnect to the Jenkins controller after the given timeout.

if [ $# -eq 1 ] && [ "${1#-}" = "$1" ] ; then

Expand Down Expand Up @@ -114,6 +115,10 @@ else
SECRET="-secret ${JENKINS_SECRET}" ;;
esac
fi

if [ -n "$JENKINS_NO_RECONNECT_AFTER" ]; then
NO_RECONNECT_AFTER="-noReconnectAfter $JENKINS_NO_RECONNECT_AFTER"
fi

if [ -n "$JENKINS_AGENT_NAME" ]; then
case "$@" in
Expand All @@ -126,6 +131,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 $NO_RECONNECT_AFTER "$@"

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

# Usage jenkins-agent.ps1 [options] -Url http://jenkins -Secret [SECRET] -Name [AGENT_NAME]
Expand All @@ -52,6 +53,7 @@ Param(
# * JENKINS_INSTANCE_IDENTITY: The base64 encoded InstanceIdentity byte array of the Jenkins controller. When this is set,
# the agent skips connecting to an HTTP(S) port for connection info.
# * JENKINS_PROTOCOLS: Specify the remoting protocols to attempt when instanceIdentity is provided.
# * JENKINS_NO_RECONNECT_AFTER: Do not attempt to reconnect to the Jenkins controller after the given timeout.

if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
Invoke-Expression "$Cmd"
Expand All @@ -70,6 +72,7 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
'DirectConnection' = 'JENKINS_DIRECT_CONNECTION';
'InstanceIdentity' = 'JENKINS_INSTANCE_IDENTITY';
'Protocols' = 'JENKINS_PROTOCOLS';
'NoReconnectAfter' = 'JENKINS_NO_RECONNECT_AFTER';
}

# this does some trickery to update the variable from the CmdletBinding
Expand Down Expand Up @@ -138,6 +141,10 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
$AgentArguments += @('-protocols', $Protocols)
}

if(![System.String]::IsNullOrWhiteSpace($NoReconnectAfter)) {
$AgentArguments += @('-noReconnectAfter', $NoReconnectAfter)
}

if(![System.String]::IsNullOrWhiteSpace($JenkinsJavaBin)) {
$JAVA_BIN = $JenkinsJavaBin
} else {
Expand Down

0 comments on commit 611dc9d

Please sign in to comment.