Skip to content

Commit

Permalink
Fix jenkinsci#31 - Do not fail on Duplicated AGENT_NAME and SECRET.
Browse files Browse the repository at this point in the history
It handles only the case when the parameter is similar to Env var.
In other cases the launch should fail anyway, because there are conflicting options
  • Loading branch information
oleg-nenashev authored and lemeurherve committed Apr 10, 2017
1 parent f93f2eb commit e3485df
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion jenkins-slave
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,27 @@ else
JNLP_PROTOCOL_OPTS="-Dorg.jenkinsci.remoting.engine.JnlpProtocol3.disabled=true"
fi

exec java $JAVA_OPTS $JNLP_PROTOCOL_OPTS -cp /usr/share/jenkins/slave.jar hudson.remoting.jnlp.Main -headless $TUNNEL $URL $JENKINS_SECRET $JENKINS_AGENT_NAME "$@"
# If both required options are defined, do not pass the parameters
OPT_JENKINS_SECRET=""
if [ -n "$JENKINS_SECRET" ]; then
if [[ "$@" != *"${JENKINS_SECRET}"* ]]; then
OPT_JENKINS_SECRET="${JENKINS_SECRET}"
else
echo "Warning: SECRET is defined twice in command-line arguments and the environment variable"
fi
fi

OPT_JENKINS_AGENT_NAME=""
if [ -n "$JENKINS_AGENT_NAME" ]; then
if [[ "$@" != *"${JENKINS_AGENT_NAME}"* ]]; then
OPT_JENKINS_AGENT_NAME="${JENKINS_AGENT_NAME}"
else
echo "Warning: AGENT_NAME is defined twice in command-line arguments and the environment variable"
fi
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 $JAVA_OPTS $JNLP_PROTOCOL_OPTS -cp /usr/share/jenkins/slave.jar hudson.remoting.jnlp.Main -headless $TUNNEL $URL $OPT_JENKINS_SECRET $OPT_JENKINS_AGENT_NAME "$@"
fi

0 comments on commit e3485df

Please sign in to comment.