Skip to content

Commit

Permalink
Ensure consistent home dir regardless of server configuration (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanhphan1147 authored Dec 8, 2023
1 parent 713babd commit 230d62d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ lib/ops-*.dist-info
^unit/
.vscode
venv
*.rock
14 changes: 9 additions & 5 deletions jenkins_agent_k8s_rock/files/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ typeset JENKINS_URL="${JENKINS_URL:?"URL of a jenkins server must be provided"}"
typeset JENKINS_AGENT="${JENKINS_AGENT:?"Jenkins agent name must be provided"}"
typeset JENKINS_TOKEN="${JENKINS_TOKEN:?"Jenkins agent token must be provided"}"

typeset JENKINS_WORKDIR="/var/lib/jenkins"
typeset JENKINS_HOME="/var/lib/jenkins"

# Ensure working directory is at $JENKINS_HOME
# -workDir parameter might be unreliable from experiences
# and jenkins can sometime ignore it (to be verified!)
cd $JENKINS_HOME
# Path of the agent.jar
typeset AGENT_JAR=/var/lib/jenkins/agent.jar
typeset AGENT_JAR="${JENKINS_HOME}/agent.jar"

# Specify the pod as ready
touch /var/lib/jenkins/agents/.ready
touch "${JENKINS_HOME}/agents/.ready"

# Start Jenkins agent
echo "${JENKINS_AGENT}"
${JAVA} -jar ${AGENT_JAR} -jnlpUrl "${JENKINS_URL}/computer/${JENKINS_AGENT}/slave-agent.jnlp" -workDir "${JENKINS_WORKDIR}" -noReconnect -secret "${JENKINS_TOKEN}" || echo "Invalid or already used credentials."
${JAVA} -jar ${AGENT_JAR} -jnlpUrl "${JENKINS_URL}/computer/${JENKINS_AGENT}/slave-agent.jnlp" -workDir "${JENKINS_HOME}" -noReconnect -secret "${JENKINS_TOKEN}" || echo "Invalid or already used credentials."

# Remove ready mark if unsuccessful
rm /var/lib/jenkins/agents/.ready
rm ${JENKINS_HOME}/agents/.ready
12 changes: 9 additions & 3 deletions jenkins_agent_k8s_rock/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: jenkins-agent-k8s
summary: Jenkins-agent-k8s rock
description: Jenkins-agent-k8s OCI image for the Jenkins-agent-k8s charm
version: "1.0"
version: "1.1"
base: ubuntu:22.04
build-base: ubuntu:22.04
license: Apache-2.0
Expand All @@ -22,7 +22,6 @@ parts:
override-prime: |
craftctl default
/bin/bash -c "mkdir -p --mode=775 var/{lib/jenkins,lib/jenkins/agents,log/jenkins}"
/bin/bash -c "chown -R 584792 var/{lib/jenkins,lib/jenkins/agents,log/jenkins}"
entrypoint:
plugin: dump
source: files
Expand All @@ -31,4 +30,11 @@ parts:
override-prime: |
craftctl default
/bin/bash -c "chmod +x var/lib/jenkins/entrypoint.sh"
/bin/bash -c "chown -R 584792 var/lib/jenkins/entrypoint.sh"
jenkins-agent-configure:
plugin: nil
after:
- "jenkins"
- "entrypoint"
override-prime: |
craftctl default
/bin/bash -c "chown -R 584792:584792 $CRAFT_PRIME/var/{lib/jenkins,log/jenkins}"

0 comments on commit 230d62d

Please sign in to comment.