Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #445 from basil/remoting-args
Browse files Browse the repository at this point in the history
Migrate to new Remoting calling convention
  • Loading branch information
dduportal authored Oct 25, 2023
2 parents 7057d4a + f207eed commit 2addb5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 4 additions & 6 deletions jenkins-agent
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Usage jenkins-agent.sh [options] -url http://jenkins [SECRET] [AGENT_NAME]
# Usage jenkins-agent.sh [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
Expand Down Expand Up @@ -107,27 +107,25 @@ else
fi

# if both required options are defined, do not pass the parameters
OPT_JENKINS_SECRET=""
if [ -n "$JENKINS_SECRET" ]; then
case "$@" in
*"${JENKINS_SECRET}"*) echo "Warning: SECRET is defined twice in command-line arguments and the environment variable" ;;
*)
OPT_JENKINS_SECRET="${JENKINS_SECRET}" ;;
SECRET="-secret ${JENKINS_SECRET}" ;;
esac
fi

OPT_JENKINS_AGENT_NAME=""
if [ -n "$JENKINS_AGENT_NAME" ]; then
case "$@" in
*"${JENKINS_AGENT_NAME}"*) echo "Warning: AGENT_NAME is defined twice in command-line arguments and the environment variable" ;;
*)
OPT_JENKINS_AGENT_NAME="${JENKINS_AGENT_NAME}" ;;
AGENT_NAME="-name ${JENKINS_AGENT_NAME}" ;;
esac
fi

#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 -cp /usr/share/jenkins/agent.jar hudson.remoting.jnlp.Main $TUNNEL $URL $WORKDIR $WEB_SOCKET $DIRECT $PROTOCOLS $INSTANCE_IDENTITY $OPT_JENKINS_SECRET $OPT_JENKINS_AGENT_NAME "$@"
exec $JAVA_BIN $JAVA_OPTIONS -jar /usr/share/jenkins/agent.jar $SECRET $AGENT_NAME $TUNNEL $URL $WORKDIR $WEB_SOCKET $DIRECT $PROTOCOLS $INSTANCE_IDENTITY "$@"

fi
8 changes: 3 additions & 5 deletions jenkins-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
$AgentArguments += Invoke-Expression "echo $JenkinsJavaOpts"
}

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

if(![System.String]::IsNullOrWhiteSpace($Tunnel)) {
$AgentArguments += @("-tunnel", "`"$Tunnel`"")
Expand Down Expand Up @@ -136,10 +138,6 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
$AgentArguments += @('-protocols', $Protocols)
}

# these need to be the last things added since they are positional
# parameters to agent.jar
$AgentArguments += @($Secret, $Name)

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

0 comments on commit 2addb5b

Please sign in to comment.