Skip to content

Commit

Permalink
use cms_static to get jenkins server
Browse files Browse the repository at this point in the history
  • Loading branch information
smuzaffar committed Oct 14, 2024
1 parent 26f2983 commit f10a594
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
28 changes: 23 additions & 5 deletions condor/connect-job.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash -ex

function set_jenkins_callback()
{
pushd $WORKSPACE/cache/cms-bot
git pull --rebase || git pull --rebase
export JENKINS_CALLBACK=$(python3 -c "import cms_static;print(cms_static.get_jenkins('${JENKINS_PREFIX}'))")
popd
}

function jenkins_data()
{
echo "${JENKINS_PAYLOAD}" | sed "s|@STATE@|$1|;s|@JENKINS_CALLBACK@|${JENKINS_CALLBACK}|"
}

env
ls -la
if [ "${_CONDOR_JOB_AD}" != "" ] ; then
Expand Down Expand Up @@ -36,6 +50,7 @@ for x in .netrc tnsnames.ora .cms_cond/db.key ; do
done
JENKINS_SLAVE_JAR_MD5=$(md5sum ${WORKSPACE}/slave.jar | sed 's| .*||')
$WORKSPACE/cache/cms-bot/jenkins/system-info.sh "${JENKINS_SLAVE_JAR_MD5}" "${WORKSPACE}"

SLAVE_LABELS=$($WORKSPACE/cache/cms-bot/jenkins/system-info.sh "${JENKINS_SLAVE_JAR_MD5}" "${WORKSPACE}" | grep '^DATA_SLAVE_LABELS=' | sed 's|^DATA_SLAVE_LABELS=|condor |')
xcore=${JENKINS_AGENT_CORES}
[ "${xcore}" = "" ] && xcore=$(nproc)
Expand All @@ -45,21 +60,22 @@ elif [ ${xcore} -gt 8 ] ; then
SLAVE_LABELS="${SLAVE_LABELS} cmsbuild"
fi
if [ "X${EXTRA_LABELS}" != "X" ] ; then SLAVE_LABELS="${SLAVE_LABELS} ${EXTRA_LABELS}" ;fi
set_jenkins_callback

JENKINS_WEBHOOK="${JENKINS_WEBHOOK-https://cmssdt.cern.ch/SDT/cgi-bin/condor_webhook}"
JOB_ID=$(grep '^ *ClusterId *=' ${_CONDOR_JOB_AD} | sed 's|.*= *||;s| ||g').0
SCHEDD_NAME=$(grep '^ *GlobalJobId *=' ${_CONDOR_JOB_AD} | sed 's|.*= *||;s|#.*||;s|"||g')
TOKEN="$(sha256sum ${AFS_HOME}/private/secrets/github_hook_secret | sed 's| .*||')"
SIGNATURE=$(echo -n "${JOB_ID}:${WORKSPACE} ${TOKEN}" | sha256sum | sed 's| .*||')
JENKINS_PAYLOAD='{"jenkins_url":"'${JENKINS_CALLBACK}'","signature":"'${SIGNATURE}'","work_dir":"'${WORKSPACE}'","schedd_name":"'${SCHEDD_NAME}'","condor_job_id":"'${JOB_ID}'","labels":"'${SLAVE_LABELS}'","status":"@STATE@"}'
JENKINS_PAYLOAD='{"jenkins_url":"@JENKINS_CALLBACK@","signature":"'${SIGNATURE}'","work_dir":"'${WORKSPACE}'","schedd_name":"'${SCHEDD_NAME}'","condor_job_id":"'${JOB_ID}'","labels":"'${SLAVE_LABELS}'","status":"@STATE@"}'

CURL_OPTS='-s -k -f --retry 3 --retry-delay 5 --max-time 30 -X POST'
if [ ! -f ${LOCAL_DATA}/online ] ; then
SEND_DATA=$(echo "${JENKINS_PAYLOAD}" | sed 's|@STATE@|online|')
SEND_DATA=$(jenkins_data online)
curl ${CURL_OPTS} -d "${SEND_DATA}" --header 'Content-Type: application/json' "${JENKINS_WEBHOOK}"
touch ${LOCAL_DATA}/online
else
SEND_DATA=$(echo "${JENKINS_PAYLOAD}" | sed 's|@STATE@|reconfigure|')
SEND_DATA=$(jenkins_data reconfigure)
curl ${CURL_OPTS} -d "${SEND_DATA}" --header 'Content-Type: application/json' "${JENKINS_WEBHOOK}"
fi

Expand Down Expand Up @@ -111,7 +127,8 @@ while true ; do
elif [ $CTIME -gt ${OFFLINE_NOTICE_TIME} -a "$FORCE_EXIT" = "false" ] ; then
echo "Sending going to Offline notification"
FORCE_EXIT=true
SEND_DATA=$(echo "${JENKINS_PAYLOAD}" | sed 's|@STATE@|offline|')
set_jenkins_callback
SEND_DATA=$(jenkins_data offline)
curl ${CURL_OPTS} -d "${SEND_DATA}" --header 'Content-Type: application/json' "${JENKINS_WEBHOOK}"
touch ${LOCAL_DATA}/offline
fi
Expand All @@ -127,7 +144,8 @@ echo "Going to shutdown."
if [ "${JENKINS_DEBUG}" != "true" ] ; then set -x ; fi
rm -rf ${WORKSPACE}
if [ ! -f ${WORKSPACE}/.shut-down ] ; then
SEND_DATA=$(echo "${JENKINS_PAYLOAD}" | sed 's|@STATE@|shutdown|')
set_jenkins_callback
SEND_DATA=$(jenkins_data shutdown)
curl ${CURL_OPTS} -d "${SEND_DATA}" --header 'Content-Type: application/json' "${JENKINS_WEBHOOK}"
fi
rm -rf ${WORKSPACE}
3 changes: 1 addition & 2 deletions condor/connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ REQUEST_CPUS="${REQUEST_CPUS-1}"
REQUEST_UNIVERSE="${REQUEST_UNIVERSE-vanilla}"
REQUEST_MAXRUNTIME="${REQUEST_MAXRUNTIME-432000}"
JENKINS_DEBUG="${DEBUG-false}"
JENKINS_CALLBACK="${JENKINS_PREFIX}"

if [ $REQUEST_CPUS -lt 1 ] ; then REQUEST_CPUS=1 ; fi
if [ "${REQUEST_MEMORY}" == "" ] ; then let REQUEST_MEMORY=${REQUEST_CPUS}*2500 ; fi
Expand Down Expand Up @@ -58,7 +57,7 @@ sed -i -e "s|@REQUEST_MEMORY@|$REQUEST_MEMORY|" job.sub
sed -i -e "s|@REQUEST_UNIVERSE@|$REQUEST_UNIVERSE|" job.sub
sed -i -e "s|@REQUEST_MAXRUNTIME@|$REQUEST_MAXRUNTIME|" job.sub
sed -i -e "s|@INPUT_FILES@|$INPUT_FILES|" job.sub
echo "environment = \"JENKINS_DEBUG='${JENKINS_DEBUG}' JENKINS_AUTO_DELETE='${JENKINS_AUTO_DELETE}' EXTRA_LABELS='${EXTRA_LABELS}' JENKINS_CALLBACK=${JENKINS_CALLBACK} REQUEST_MAXRUNTIME=${REQUEST_MAXRUNTIME}\"" >> job.sub
echo "environment = \"JENKINS_DEBUG='${JENKINS_DEBUG}' JENKINS_AUTO_DELETE='${JENKINS_AUTO_DELETE}' EXTRA_LABELS='${EXTRA_LABELS}' JENKINS_PREFIX='${JENKINS_PREFIX}' REQUEST_MAXRUNTIME=${REQUEST_MAXRUNTIME}\"" >> job.sub

if [ "X${CONDOR_JOB_CONF}" != "X" ] ; then
if [ -f ${CONDOR_JOB_CONF} ] ; then
Expand Down

0 comments on commit f10a594

Please sign in to comment.