diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..70f6d43 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,98 @@ +pipeline { + agent { + kubernetes { + yaml """ +apiVersion: v1 +kind: Pod +spec: + containers: + - name: node-2290-build + image: python:3.9-slim-buster + command: + - cat + tty: true + securityContext: + privileged: true + runAsUser: 0 + - name: jnlp + image: jenkins/inbound-agent:latest + args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)'] + securityContext: + privileged: true + runAsUser: 0 + - name: podman + image: quay.io/podman/stable + command: + - cat + tty: true + securityContext: + privileged: true + runAsUser: 0 + - name: kubectl + image: dtzar/helm-kubectl + command: + - cat + tty: true + securityContext: + privileged: true + runAsUser: 0 +""" + } + } + parameters { + + string(name: 'CHASE_USER', defaultValue: '', description: 'Chase username') + string(name: 'CHASE_PASS', defaultValue: '', description: 'Chase password') + } + + + environment { + VENV_DIR = 'venv' + OUTPUTDIR = 'results' + CHASE_USER= "${params.CHASE_USER}" + CHASE_PASS= "${params.CHASE_PASS}" + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Setup Python') { + steps { + sh 'python3 -m venv $VENV_DIR' + sh '. $VENV_DIR/bin/activate && python -m pip install --upgrade pip' + // try installing from requirements.txt if present + sh '. $VENV_DIR/bin/activate && if [ -f requirements.txt ]; then pip install -r requirements.txt || true; fi' + // ensure Robot and common libs are installed + sh '. $VENV_DIR/bin/activate && pip install robotframework selenium robotframework-seleniumlibrary webdriver-manager || true' + } + } + + stage('Create PVC') { + steps { + // Apply PVC manifest if kubectl is available + sh "if command -v kubectl >/dev/null 2>&1; then kubectl apply -f k8s/pvc-chrome-profile.yaml || true; kubectl wait --for=condition=bound pvc/chrome-profile-pvc --timeout=60s || true; else echo 'kubectl not found, skipping PVC creation'; fi" + } + } + + stage('Run Robot Tests') { + steps { + sh '. $VENV_DIR/bin/activate && mkdir -p ${OUTPUTDIR} && ./jenkins/run_robot.sh' + } + post { + always { + archiveArtifacts artifacts: 'results/**', fingerprint: true + } + } + } + } + + post { + failure { + echo 'Robot tests failed. See archived artifacts in results/ for details.' + } + } +} diff --git a/jenkins/run_robot.sh b/jenkins/run_robot.sh new file mode 100644 index 0000000..728c9f3 --- /dev/null +++ b/jenkins/run_robot.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Activate virtualenv +if [ -f venv/bin/activate ]; then + # shellcheck disable=SC1091 + . venv/bin/activate +fi + +# Ensure results directory exists +mkdir -p results + +# If running in Kubernetes or a container where a PVC is mounted at /workspace/results/chrome-profile, +# use that as the Chrome user data dir so Chrome uses a persistent profile. +if [ -d /workspace/results/chrome-profile ]; then + export CHROME_USER_DATA_DIR=/workspace/results/chrome-profile +elif [ -d ${PWD}/results/chrome-profile ]; then + export CHROME_USER_DATA_DIR=${PWD}/results/chrome-profile +fi + +# Create profile dir if not present +mkdir -p "${CHROME_USER_DATA_DIR-./results/chrome-profile}" + +# Run robot framework on tests folder; adjust args as needed +robot -d results tests || RC=$? + +# Exit with robot return code if set +if [ -n "${RC-}" ]; then + exit $RC +fi diff --git a/k8s/pod-with-chrome-profile.yaml b/k8s/pod-with-chrome-profile.yaml new file mode 100644 index 0000000..96d2325 --- /dev/null +++ b/k8s/pod-with-chrome-profile.yaml @@ -0,0 +1,28 @@ +apiVersion: v1 +kind: Pod +metadata: + name: robot-runner-with-profile + labels: + app: robot-tests +spec: + 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 + volumeMounts: + - name: chrome-profile + mountPath: /workspace/results/chrome-profile + - name: workspace + mountPath: /workspace + restartPolicy: Never + volumes: + - name: chrome-profile + persistentVolumeClaim: + claimName: chrome-profile-pvc + - name: workspace + emptyDir: {} diff --git a/k8s/pvc-chrome-profile.yaml b/k8s/pvc-chrome-profile.yaml new file mode 100644 index 0000000..afd59b2 --- /dev/null +++ b/k8s/pvc-chrome-profile.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: chrome-profile-pvc + labels: + app: robot-tests +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + # Optional: specify StorageClass if needed + # storageClassName: standard