Files
Bruno_Tests/pipeline.groovy
2026-09-03 11:23:43 +03:00

86 lines
3.0 KiB
Groovy
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pipeline {
agent { label 'bruno-docker' }
options {
timeout(time: 30, unit: 'MINUTES')
}
environment {
TESTS_DIR = 'nonexistent_folder_xyz12345678_9_0'
LAST_EXIT_CODE = '0'
}
stages {
stage('Checkout') {
steps {
git branch: 'main',
url: 'https://github.com/AlexB1960/burlaka_jenkins.git',
credentialsId: 'GitTea'
}
}
stage('Validate Directory') {
steps {
script {
echo "DEBUG: Начальное значение LAST_EXIT_CODE: ${env.LAST_EXIT_CODE}"
def status = sh(
script: '''
echo "=== Проверка папки '${TESTS_DIR}' ==="
ls -la
if [ ! -d "${TESTS_DIR}" ]; then
echo "ERROR: Directory ${TESTS_DIR} not found!"
exit 4
else
echo "OK: Directory exists."
exit 0
fi
''',
returnStatus: true
)
// ЭТА СТРОКА КРИТИЧНА: она должна быть именно такой
env.LAST_EXIT_CODE = status.toString()
echo "DEBUG: Значение status из sh: ${status}"
echo "DEBUG: LAST_EXIT_CODE установлен в: ${env.LAST_EXIT_CODE}"
if (status != 0) {
echo "DEBUG: Обнаружена ошибка. Вызываем error..."
error "Stage failed with exit code ${status}. Папка не найдена."
}
}
}
}
stage('Run Bruno Tests') {
when {
expression { env.LAST_EXIT_CODE == '0' }
}
steps {
script {
dir(env.TESTS_DIR) {
sh 'mkdir -p reports'
sh 'chmod -R 777 reports'
sh 'docker run --rm -v $(pwd):/bruno -w /bruno usebruno/cli:latest run --reporter-html reports/report.html --reporter-junit reports/test-results.xml'
}
}
}
}
}
post {
failure {
script {
echo "DEBUG: LAST_EXIT_CODE в post failure: ${env.LAST_EXIT_CODE}"
echo "Тесты не пройдены!"
if (env.LAST_EXIT_CODE != "4") {
archiveArtifacts artifacts: "${env.TESTS_DIR}/reports/**", onlyIfSuccessful: false
} else {
echo "Код ошибки 4 (папка не найдена). Отчёты не архивируем."
}
}
}
}
}