jenkins

Started working on an init.d script to launch a Jenkins slave.jar today. Its interesting as the command line for firing it off is a bit crazy.

A simple example of the console slave.jar

The init script is written in bash to simplify compatibility in doing that we now have some limitations but having fun with it.

full_command="${LOCAL_JAVA_PATH} -jar \
           ${AGENT_EXECUTION_DIR}/$JENKINS_AGENT_BIN_NAME -jnlpUrl \
           ${JENKINS_MASTER_COMPUTER}/${AGENT_NAME}/slave-agent.jnlp \
           -jnlpCredentials $JENKINS_TOKEN"

There is a config file associated with "full_command" makes life a bit easier in setting up.

". /app/jenkinsAgent/admin/agent.cfg"

The full script is here init_template

function GRAB_PID()
{
  local  PID=`ps -ef | grep 'java -jar.*slave.jar\|[j]ava -jar slave.jar' |\
              grep -v grep | \
              awk '{print $2}'`
  echo    "$PID"
}

Created a simple function for PID, have an "or" in the grep and do a quick awk for the print. To call the function a "$(function name)" is used.

echo $(GRAB_PID)