diff --git a/Jenkinsfile b/Jenkinsfile index 931a67c..36f2f99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,6 +14,10 @@ securityContext: privileged: true runAsUser: 0 + - name: git-sync + image: alpine/git + command: + - cat - name: jnlp image: jenkins/inbound-agent:latest args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)'] @@ -93,7 +97,7 @@ usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) { sh """ - git clone https://${GIT_USER}:"${GIT_PASS}"@gitbucket.heaerie.com/git/agalyadoss/ledger.git + git clone https://${GIT_USER}:${GIT_PASS}@gitbucket.heaerie.com/git/agalyadoss/ledger.git cd ledger && git checkout main git config user.name "Jenkins CI" diff --git a/k8s/pod-with-chrome-profile.yaml b/k8s/pod-with-chrome-profile.yaml index 96d2325..280ed98 100644 --- a/k8s/pod-with-chrome-profile.yaml +++ b/k8s/pod-with-chrome-profile.yaml @@ -5,15 +5,56 @@ labels: app: robot-tests spec: + initContainers: + - name: git-sync + image: alpine/git + command: ["/bin/sh", "-c"] + args: + - | + set -e + if [ -z "${GIT_REPO}" ]; then + echo "GIT_REPO not set; skipping clone" + exit 0 + fi + mkdir -p /workspace/src + if [ -d /workspace/src/.git ]; then + cd /workspace/src + git fetch --all --prune + git reset --hard origin/${GIT_REF:-main} + else + git clone --branch ${GIT_REF:-main} ${GIT_REPO} /workspace/src + fi + env: + - name: GIT_REPO + value: "https://github.com/yourorg/yourrepo.git" + - name: GIT_REF + value: "main" + volumeMounts: + - name: workspace + mountPath: /workspace + containers: - name: robot-runner image: python:3.11-slim command: ["/bin/sh", "-c"] args: - - mkdir -p /workspace && cd /workspace && \ - python -m venv venv && . venv/bin/activate && pip install robotframework selenium robotframework-seleniumlibrary webdriver-manager && \ - # run tests (adjust as needed) - robot -d results tests || true + - | + set -euo pipefail + # use workspace/src if populated by initContainer, otherwise use /workspace + WORKDIR=/workspace/src + if [ ! -d "$WORKDIR" ]; then WORKDIR=/workspace; fi + cd "$WORKDIR" + python -m venv venv + . venv/bin/activate + pip install --upgrade pip + pip install robotframework selenium robotframework-seleniumlibrary webdriver-manager || true + mkdir -p results + # export chrome profile dir if mounted + if [ -d /workspace/results/chrome-profile ]; then + export CHROME_USER_DATA_DIR=/workspace/results/chrome-profile + fi + robot -d results tests || RC=$? + exit ${RC-0} volumeMounts: - name: chrome-profile mountPath: /workspace/results/chrome-profile