diff --git a/jenkins-agent b/jenkins-agent index 22025cd1b..80763c9aa 100755 --- a/jenkins-agent +++ b/jenkins-agent @@ -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 @@ -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 @@ -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 diff --git a/jenkins-agent.ps1 b/jenkins-agent.ps1 index 6dbf62f8b..8fe2637f2 100644 --- a/jenkins-agent.ps1 +++ b/jenkins-agent.ps1 @@ -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] @@ -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" @@ -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 @@ -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 {