pipeline { agent { label 'assignment8-trusted' } options { disableConcurrentBuilds(); timeout(time: 45, unit: 'MINUTES'); timestamps() } stages { stage('Prepare reviewed v1 configuration') { steps { deleteDir() git url: 'https://myfileagent.tech/myfileagent/myfileagent-pipeline.git', branch: 'main' sh '''set -eu git checkout --detach 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2 test "$(git rev-parse HEAD)" = 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2 mkdir -p reports cat > reports/v1-production.yml <<'EOF' target_env: production release_image: myfileagent.tech/myfileagent/pricing@sha256:715a3c80d5fff4319e275583e73e58cd80bffadea6e25796dd4867135ff036c2 expected_version: v1 expected_commit: 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2 configuration_commit: 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2 expected_total: 30 public_url: https://app.myfileagent.tech proxy_network: myfileagent-gitea_gitea-private EOF curl -fsS https://app.myfileagent.tech/ > reports/before-identity.json curl -fsS 'https://app.myfileagent.tech/price?quantity=3' > reports/before-price.json python3 -c 'import json; a=json.load(open("reports/before-identity.json")); p=json.load(open("reports/before-price.json")); assert a["version"]=="v2" and a["commit"]=="ee128d18bddd1763b916b40f05829f2e769f0654" and p["total"]==36' ''' } } stage('Human rollback approval') { steps { script { def approver = timeout(time: 30, unit: 'MINUTES') { input message: 'Approve the Assignment 8 production rollback exercise from verified v2/36 to v1/30 using configuration 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2 and image sha256:715a3c80d5fff4319e275583e73e58cd80bffadea6e25796dd4867135ff036c2? Recreating the container may interrupt traffic.', ok: 'Roll back', submitter: 'ssw590', submitterParameter: 'APPROVER' } writeFile file: 'reports/approval.txt', text: "Approver: ${approver}\nDecision: approved\nTime UTC: ${sh(script: 'date -u +%FT%TZ', returnStdout: true).trim()}\n" } } } stage('Roll back and verify') { steps { withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) { sh '''#!/bin/sh set +x set -eu export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" ( while :; do stamp=$(date -u +%FT%TZ) code=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 https://app.myfileagent.tech/health 2>/dev/null || true) printf '%s %s\n' "$stamp" "$code" >> reports/availability-samples.txt sleep 1 done ) & probe=$! trap 'kill "$probe" 2>/dev/null || true; wait "$probe" 2>/dev/null || true' EXIT date -u +%FT%TZ > reports/rollback-start.txt ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @reports/v1-production.yml > reports/rollback-ansible.txt 2>&1 date -u +%FT%TZ > reports/rollback-verified.txt curl -fsS https://app.myfileagent.tech/health > reports/after-health.json curl -fsS https://app.myfileagent.tech/ > reports/after-identity.json curl -fsS 'https://app.myfileagent.tech/price?quantity=3' > reports/after-price.json python3 -c 'import json; h=json.load(open("reports/after-health.json")); a=json.load(open("reports/after-identity.json")); p=json.load(open("reports/after-price.json")); assert h["status"]=="ok" and a["version"]=="v1" and a["commit"]=="0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2" and p["total"]==30' ''' } } } } post { always { archiveArtifacts artifacts: 'reports/*', allowEmptyArchive: true } } }