diff --git a/Jenkinsfile b/Jenkinsfile index 70f6d43..8b97633 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ kind: Pod spec: containers: - - name: node-2290-build + - name: python-3.9-slim-buster-build image: python:3.9-slim-buster command: - cat @@ -47,6 +47,8 @@ environment { + REGISTRY = "docker.io/agalyadoss" + IMAGE = "ledger" VENV_DIR = 'venv' OUTPUTDIR = 'results' CHASE_USER= "${params.CHASE_USER}" @@ -54,33 +56,89 @@ } stages { - stage('Checkout') { - steps { - checkout scm + stage('Generate Version') { + steps { + script { + def arch = sh(script: 'uname -m', returnStdout: true).trim() + def now = new Date() + def year = now.format("yyyy") + def month = now.format("MM") + def weekOfYear = now[Calendar.WEEK_OF_YEAR] // Week of Year + VERSION = "${year}.${month}.${weekOfYear}.${BUILD_NUMBER}.${arch}" + echo "Version: ${VERSION}" + + // Auto-generate version if DOCKER_TAG param is blank + if (params.DOCKER_TAG?.trim()) { + TAG = params.DOCKER_TAG + echo "Using provided DOCKER_TAG: ${TAG}" + } else { + TAG = "${year}.${month}.${weekOfYear}.${BUILD_NUMBER}.${arch}" + echo "Auto-generated version: ${TAG}" + } + } + } + } + + stage('Print Build Number') { + steps { + echo "Current Build Number: ${VERSION}" + } + } + + +stage('Chechout Repo cockoo') { + steps { + container('python-3.9-slim-buster-build') { + withCredentials([usernamePassword(credentialsId: 'H000146', + usernameVariable: 'GIT_USER', + passwordVariable: 'GIT_PASS')]) { + sh """ + 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" + git config user.email "jenkins@heaerie.com" + git tag ${VERSION} + git push https://${GIT_USER}:${GIT_PASS}@gitbucket.heaerie.com/git/agalyadoss/ledger.git ${VERSION} + + """ + } + } + } + } + + stage('Setup Python') { + steps { + container('python-3.9-slim-buster-build') { + + sh """ + cd ledge + python3 -m venv $VENV_DIR + . $VENV_DIR/bin/activate + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt || true; fi' + pip install robotframework selenium robotframework-seleniumlibrary webdriver-manager || true' + """ + } } } - 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 { + container('python-3.9-slim-buster-build') { // 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 { + container('python-3.9-slim-buster-build') { sh '. $VENV_DIR/bin/activate && mkdir -p ${OUTPUTDIR} && ./jenkins/run_robot.sh' + } } post { always {