pipeline {
    agent any

    options {
        ansiColor('xterm')
        disableConcurrentBuilds()
        timestamps()
        timeout(time: 60, unit: 'MINUTES')
        buildDiscarder(logRotator(numToKeepStr: '60'))
    }

    stages {
        stage('Load Shared Libraries') {
            steps {
                library "jenkins-global-libraries@master"
            }
        }

        stage('Run Cypress E2E Prod Tests') {
            environment {
                TAGS = "@insights_lighthouse"
            }
            steps {
                withCredentials([aws(credentialsId: 'cucumber-tests')]) {
                    e2eTests tags: env.TAGS, envVars:['CONFIG_FILE':'prod', 'TRIES':'1'], reportTitle: 'Prod'
                }
            }
        }
    }

    post {
        always {
            sh 'make clean_docker_containers || true' // Ensure cleanup runs even if previous steps fail
        }
        failure {
            slackNotify channel: '#cypress-test-e2e-results,#prod-e2e-results'
        }
        fixed {
            slackNotify channel: '#cypress-test-e2e-results,#prod-e2e-results'
        }
    }
}