with pipeline.groovy
This commit is contained in:
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
86
requests/pipeline.groovy
Normal file
86
requests/pipeline.groovy
Normal file
@@ -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 (папка не найдена). Отчёты не архивируем."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
run_bruno.sh
12
run_bruno.sh
@@ -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
|
|
||||||
Reference in New Issue
Block a user