From 6bef60edc52ec4d1e3ca2a14099563138c811c57 Mon Sep 17 00:00:00 2001 From: AlexB1960 Date: Thu, 3 Sep 2026 11:11:31 +0300 Subject: [PATCH] with pipeline.groovy --- Create Release.yml | 33 ------------- Create Service Without Body.yml | 48 ------------------ Create Service Without Code.yml | 52 -------------------- Create Service.yml | 53 -------------------- Get All Services.yml | 15 ------ Get Service by Code.yml | 15 ------ Get Service by ID.yml | 15 ------ Negative - Invalid UUID.yml | 15 ------ Negative - Missing Body.yml | 21 -------- Update Release.yml | 26 ---------- Update Service.yml | 26 ---------- parse_stats.awk | 28 ----------- requests/pipeline.groovy | 86 +++++++++++++++++++++++++++++++++ run_bruno.sh | 12 ----- 14 files changed, 86 insertions(+), 359 deletions(-) delete mode 100644 Create Release.yml delete mode 100644 Create Service Without Body.yml delete mode 100644 Create Service Without Code.yml delete mode 100644 Create Service.yml delete mode 100644 Get All Services.yml delete mode 100644 Get Service by Code.yml delete mode 100644 Get Service by ID.yml delete mode 100644 Negative - Invalid UUID.yml delete mode 100644 Negative - Missing Body.yml delete mode 100644 Update Release.yml delete mode 100644 Update Service.yml delete mode 100755 parse_stats.awk create mode 100644 requests/pipeline.groovy delete mode 100755 run_bruno.sh diff --git a/Create Release.yml b/Create Release.yml deleted file mode 100644 index 3ba7bbe..0000000 --- a/Create Release.yml +++ /dev/null @@ -1,33 +0,0 @@ -info: - name: Create Release - type: http - seq: 8 - -http: - method: POST - url: "{{baseUrl}}/api/v1/releases" - headers: - - name: Content-Type - value: application/json - body: - type: json - data: |- - { - "service": "e58ac01a-606b-4cf7-9dee-cb4484672fa1", - "version": "1.0.0", - "changelog": "Initial release" - } - auth: inherit - -runtime: - scripts: - - type: after-response - code: "let json = res.getBody();\r - - bru.setEnvVar('releaseId', json.data.id);" - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Create Service Without Body.yml b/Create Service Without Body.yml deleted file mode 100644 index 8c94c05..0000000 --- a/Create Service Without Body.yml +++ /dev/null @@ -1,48 +0,0 @@ -info: - name: Create Service Without Body - type: http - seq: 3 - -http: - method: POST - url: "{{baseUrl}}/api/v1/services" - headers: - - name: Content-Type - value: application/json - - name: requestID - value: test-req-1 - body: - type: json - data: "" - auth: inherit - -runtime: - scripts: - - type: after-response - code: "test('Status code is 200', function () {\r - - \ expect(res.getStatus()).to.equal(200);\r - - });\r - - \r - - let json = res.getBody();\r - - \r - - test('Status is SUCCESS', function () {\r - - \ expect(json.status).to.eql('SUCCESS');\r - - });\r - - \r - - bru.setEnvVar('serviceId', json.data.id);" - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Create Service Without Code.yml b/Create Service Without Code.yml deleted file mode 100644 index 10c3327..0000000 --- a/Create Service Without Code.yml +++ /dev/null @@ -1,52 +0,0 @@ -info: - name: Create Service Without Code - type: http - seq: 2 - -http: - method: POST - url: "{{baseUrl}}/api/v1/services" - headers: - - name: Content-Type - value: application/json - - name: requestID - value: test-req-1 - body: - type: json - data: |- - { - "type": "SYSTEM", - "name": "Сервис управления версиями модулей" - } - auth: inherit - -runtime: - scripts: - - type: after-response - code: "test('Status code is 200', function () {\r - - \ expect(res.getStatus()).to.equal(200);\r - - });\r - - \r - - let json = res.getBody();\r - - \r - - test('Status is SUCCESS', function () {\r - - \ expect(json.status).to.eql('SUCCESS');\r - - });\r - - \r - - bru.setEnvVar('serviceId', json.data.id);" - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Create Service.yml b/Create Service.yml deleted file mode 100644 index 8e129a8..0000000 --- a/Create Service.yml +++ /dev/null @@ -1,53 +0,0 @@ -info: - name: Create Service - type: http - seq: 1 - -http: - method: POST - url: "{{baseUrl}}/api/v1/services" - headers: - - name: Content-Type - value: application/json - - name: requestID - value: test-req-1 - body: - type: json - data: |- - { - "type": "SYSTEM", - "code": "SERVICE_1", - "name": "Test Service" - } - auth: inherit - -runtime: - scripts: - - type: after-response - code: "test('Status code is 200', function () {\r - - \ expect(res.getStatus()).to.equal(200);\r - - });\r - - \r - - let json = res.getBody();\r - - \r - - test('Status is SUCCESS', function () {\r - - \ expect(json.status).to.eql('SUCCESS');\r - - });\r - - \r - - bru.setEnvVar('serviceId', json.data.id);" - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Get All Services.yml b/Get All Services.yml deleted file mode 100644 index 1bda34d..0000000 --- a/Get All Services.yml +++ /dev/null @@ -1,15 +0,0 @@ -info: - name: Get All Services - type: http - seq: 4 - -http: - method: GET - url: "{{baseUrl}}/api/v1/services" - auth: inherit - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Get Service by Code.yml b/Get Service by Code.yml deleted file mode 100644 index 6042353..0000000 --- a/Get Service by Code.yml +++ /dev/null @@ -1,15 +0,0 @@ -info: - name: Get Service by Code - type: http - seq: 7 - -http: - method: GET - url: "{{baseUrl}}/api/v1/services/code/modules-version2.2" - auth: inherit - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Get Service by ID.yml b/Get Service by ID.yml deleted file mode 100644 index 34518bf..0000000 --- a/Get Service by ID.yml +++ /dev/null @@ -1,15 +0,0 @@ -info: - name: Get Service by ID - type: http - seq: 5 - -http: - method: GET - url: "{{baseUrl}}/api/v1/services/{{serviceId}}" - auth: inherit - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Negative - Invalid UUID.yml b/Negative - Invalid UUID.yml deleted file mode 100644 index 2e4ef54..0000000 --- a/Negative - Invalid UUID.yml +++ /dev/null @@ -1,15 +0,0 @@ -info: - name: Negative - Invalid UUID - type: http - seq: 10 - -http: - method: GET - url: "{{baseUrl}}/api/v1/services/123" - auth: inherit - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Negative - Missing Body.yml b/Negative - Missing Body.yml deleted file mode 100644 index 88afe1b..0000000 --- a/Negative - Missing Body.yml +++ /dev/null @@ -1,21 +0,0 @@ -info: - name: Negative - Missing Body - type: http - seq: 11 - -http: - method: POST - url: "{{baseUrl}}/api/v1/services" - headers: - - name: Content-Type - value: application/json - body: - type: json - data: "" - auth: inherit - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Update Release.yml b/Update Release.yml deleted file mode 100644 index e37a470..0000000 --- a/Update Release.yml +++ /dev/null @@ -1,26 +0,0 @@ -info: - name: Update Release - type: http - seq: 9 - -http: - method: PUT - url: "{{baseUrl}}/api/v1/releases/{{releaseId}}" - headers: - - name: Content-Type - value: application/json - body: - type: json - data: |- - { - "service": "{{serviceId}}", - "version": "1.0.1", - "changelog": "Bug fixes" - } - auth: inherit - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/Update Service.yml b/Update Service.yml deleted file mode 100644 index fb48ce3..0000000 --- a/Update Service.yml +++ /dev/null @@ -1,26 +0,0 @@ -info: - name: Update Service - type: http - seq: 6 - -http: - method: PUT - url: "{{baseUrl}}/api/v1/services/{{serviceId}}" - headers: - - name: Content-Type - value: application/json - body: - type: json - data: |- - { - "code": "modules-version2.2", - "name": "Сервис управления версиями модулей", - "type": "SYSTEM" - } - auth: inherit - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/parse_stats.awk b/parse_stats.awk deleted file mode 100755 index 959610a..0000000 --- a/parse_stats.awk +++ /dev/null @@ -1,28 +0,0 @@ -BEGIN { - total = 0 - passed = 0 - failed = 0 -} - -/Requests/ && /Passed/ && /Failed/ { - # Ищем строку вида: │ Requests │ 11 (10 Passed, 1 Failed) │ - match($0, /[0-9]+ \([0-9]+ Passed, [0-9]+ Failed\)/) - if (RSTART > 0) { - s = substr($0, RSTART, RLENGTH) - # Убираем скобки и лишние символы - gsub(/[()]/, "", s) - split(s, parts, /[[:space:],]+/) - total = parts[1] - passed = parts[2] - failed = parts[4] - } -} - -END { - if (total == 0) { - # Если не нашли статистику — выводим нули - printf "Total=0, Passed=0, Failed=0\n" - } else { - printf "Total=%d, Passed=%d, Failed=%d\n", total, passed, failed - } -} \ No newline at end of file diff --git a/requests/pipeline.groovy b/requests/pipeline.groovy new file mode 100644 index 0000000..228b342 --- /dev/null +++ b/requests/pipeline.groovy @@ -0,0 +1,86 @@ +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 (папка не найдена). Отчёты не архивируем." + } + } + } + } +} \ No newline at end of file diff --git a/run_bruno.sh b/run_bruno.sh deleted file mode 100755 index 51cbeb5..0000000 --- a/run_bruno.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -mkdir -p reports - -# Здесь нет лишних кавычек — это обычный shell-скрипт, он работает правильно -docker run --rm \ - --memory="1g" \ - -v "$PWD":/bruno:ro \ - -w /bruno \ - usebruno/cli:latest \ - bru run -f json -o reports/results.json