-
Notifications
You must be signed in to change notification settings - Fork 217
Script to keep Jenkins Agent persistent from cron #2634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
WalterKolczynski-NOAA
merged 10 commits into
NOAA-EMC:develop
from
TerrenceMcGuinness-NOAA:persistent_jenkins
May 29, 2024
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9e9b628
adding a persistent lanuching tool for Jenkins Java Agents
TerrenceMcGuinness-NOAA 7b3f9d2
got test node working
TerrenceMcGuinness-NOAA 50ae868
added machine specifics into config file in ci for lanuching Jenkins
TerrenceMcGuinness-NOAA 88d7f97
spelled source wrong
TerrenceMcGuinness-NOAA e80843a
added lanuch config for hercules and orion
TerrenceMcGuinness-NOAA c2c79ad
updated configured path to launch dir
TerrenceMcGuinness-NOAA 8b41ace
made a few shell norm updates
TerrenceMcGuinness-NOAA 0f203a8
made two more shell norm updates
TerrenceMcGuinness-NOAA ed5b2f7
trailing spaces needed
TerrenceMcGuinness-NOAA 3e13580
Update ci/scripts/utils/launch_java_agent.sh
TerrenceMcGuinness-NOAA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/bin/env bash | ||
| set -e | ||
|
|
||
| controller_url="https://jenkins.epic.oarcloud.noaa.gov" | ||
| controller_user="terry.mcguinness" | ||
| HOMEgfs="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." >/dev/null 2>&1 && pwd )" | ||
| host=$(hostname) | ||
|
|
||
| ######################################################################### | ||
| # Set up runtime environment varibles for accounts on supproted machines | ||
| ######################################################################### | ||
|
|
||
| source "${HOMEgfs}/ush/detect_machine.sh" | ||
| case ${MACHINE_ID} in | ||
| hera | orion | hercules | wcoss2) | ||
| echo "Launch Jenkins Java Controler on ${MACHINE_ID}" | ||
| ;; | ||
| *) | ||
| echo "Unsupported platform. Exiting with error." | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| LOG=lanuched_agent-$(date +%Y%m%d%M).log | ||
| rm -f "${LOG}" | ||
|
|
||
| source "${HOMEgfs}/ush/module-setup.sh" | ||
| module use "${HOMEgfs}/modulefiles" | ||
| module load "module_gwsetup.${MACHINE_ID}" | ||
| source "${HOMEgfs}/ci/platforms/config.${MACHINE_ID}" | ||
|
|
||
| JAVA_HOME="${JENKINS_AGENT_LANUCH_DIR}/JAVA/jdk-17.0.10" | ||
| if [ ! -d "${JAVA_HOME}" ]; then | ||
|
|
||
| JAVA_HOME=/usr/lib/jvm/jre-17 | ||
| if [ ! -d "${JAVA_HOME}" ]; then | ||
|
|
||
| echo "ERROR: JAVA_HOME not found. Exiting with error." | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| JAVA="${JAVA_HOME}/bin/java" | ||
| echo "JAVA VERSION: " | ||
| ${JAVA} -version | ||
|
|
||
| export GH="${HOME}/bin/gh" | ||
| command -v $GH | ||
|
|
||
| $GH --version | ||
|
|
||
|
|
||
| if [[ -d "${JENKINS_AGENT_LANUCH_DIR}" ]]; then | ||
| echo "Jenkins Agent Lanuch Directory: ${JENKINS_AGENT_LANUCH_DIR}" | ||
| else | ||
| echo "ERROR: Jenkins Agent Lanuch Directory not found. Exiting with error." | ||
| exit 1 | ||
| fi | ||
| cd "${JENKINS_AGENT_LANUCH_DIR}" | ||
|
|
||
| if ! [ -f agent.jar ]; then | ||
|
|
||
| curl -sO "${controller_url}/jnlpJars/agent.jar" | ||
| fi | ||
|
|
||
| JENKINS_TOKEN=$(cat jenkins_token) | ||
|
|
||
| offline=$(curl --silent -u "${controller_user}:$JENKINS_TOKEN" "${controller_url}/computer/${MACHINE_ID^}-EMC/api/json?pretty=true" | grep '\"offline\"' | awk '{gsub(/,/,"");print $3}') | ||
|
|
||
| echo "Jenkins Agent offline setting: ${offline}" | ||
|
|
||
| if [ "${offline}" == "true" ]; then | ||
|
|
||
| echo "Jenkins Agent is offline. Lanuching Jenkins Agent on $host" | ||
|
|
||
| command="nohup ${JAVA} -jar agent.jar -jnlpUrl ${controller_url}/computer/${MACHINE_ID^}-EMC/jenkins-agent.jnlp -secret @jenkins-secret-file -workDir ${JENKINS_WORK_DIR}" | ||
| echo -e "Lanuching Jenkins Agent on $host with the command:\n${command}" >& "${LOG}" | ||
|
|
||
| ${command} >> "${LOG}" 2>&1 & | ||
| nohup_PID=$! | ||
| echo "Java agent running on PID: ${nohup_PID}" >> "${LOG}" 2>&1 | ||
| echo "Java agent running on PID: ${nohup_PID}" | ||
| else | ||
| echo "Jenkins Agent is online (nothing done)" | ||
| fi | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.