feat: finalize projectwork CI jobs, docs and test integration

This commit is contained in:
2026-04-23 11:39:08 +03:00
parent 737bddd631
commit 20bdacf5c5
39 changed files with 1819 additions and 70 deletions
+166
View File
@@ -0,0 +1,166 @@
pipeline {
agent { label 'maven' }
options {
timestamps()
ansiColor('xterm')
}
stages {
stage('Prepare Metadata') {
steps {
script {
wrap([$class: 'BuildUser']) {
env.RUN_TRIGGER_USER = env.BUILD_USER_ID ?: env.BUILD_USER ?: 'system'
env.RUN_TRIGGER_NAME = env.BUILD_USER ?: env.BUILD_USER_ID ?: 'system'
}
currentBuild.displayName = "#${env.BUILD_NUMBER} maven-extra"
currentBuild.description = "by=${env.RUN_TRIGGER_NAME}; repo=${params.EXTRA_REPO_URL}; ref=${params.EXTRA_REPO_REF}"
}
}
}
stage('Run Maven Extra Tests') {
steps {
sh '''
set -eux
git config --global --add safe.directory '*' || true
rm -rf ./sources ./artifacts
mkdir -p ./artifacts
if [ "${EXTRA_REPO_URL#/}" != "${EXTRA_REPO_URL}" ] && [ ! -d "${EXTRA_REPO_URL}" ]; then
mkdir -p ./artifacts/target/allure-results
EXTRA_UUID="$(cat /proc/sys/kernel/random/uuid)"
TS_MS="$(( $(date +%s) * 1000 ))"
cat > "./artifacts/target/allure-results/${EXTRA_UUID}-result.json" <<EOF
{
"uuid": "${EXTRA_UUID}",
"historyId": "maven-extra-skipped-${BUILD_NUMBER}",
"name": "Maven extra pipeline summary",
"fullName": "pipeline.MavenExtraSummary",
"status": "skipped",
"stage": "finished",
"start": ${TS_MS},
"stop": ${TS_MS},
"labels": [
{"name": "suite", "value": "Pipeline"},
{"name": "package", "value": "pipeline"},
{"name": "testClass", "value": "MavenExtraSummary"},
{"name": "testMethod", "value": "run"}
],
"steps": [],
"parameters": []
}
EOF
{
echo "job=${JOB_NAME}"
echo "build=${BUILD_NUMBER}"
echo "repo.url=${EXTRA_REPO_URL}"
echo "repo.ref=${EXTRA_REPO_REF}"
echo "status=SKIPPED_MISSING_REPO"
} > ./artifacts/target/allure-results/environment.properties
cat > ./artifacts/target/allure-results/executor.json <<EOF
{
"name": "Jenkins",
"type": "jenkins",
"url": "${JENKINS_URL}",
"buildName": "${JOB_NAME} #${BUILD_NUMBER}",
"buildUrl": "${BUILD_URL}",
"reportUrl": "${BUILD_URL}allure",
"buildOrder": ${BUILD_NUMBER}
}
EOF
{
echo "repo=${EXTRA_REPO_URL}"
echo "ref=${EXTRA_REPO_REF}"
echo "status=SKIPPED_MISSING_REPO"
} > ./artifacts/run-info.txt
exit 0
fi
git clone "${EXTRA_REPO_URL}" ./sources
git -C ./sources checkout "${EXTRA_REPO_REF}"
GIT_SHA="$(git -C ./sources rev-parse --short HEAD)"
CID="$(docker create localhost:5005/otus/test-api:1.0.0 bash -lc "set -e; cd /workspace; mvn -Dallure.results.directory=target/allure-results ${EXTRA_MAVEN_GOAL}")"
cleanup_container() {
docker rm -f "${CID}" >/dev/null 2>&1 || true
}
trap cleanup_container EXIT INT TERM
tar -C ./sources -cf - . | docker cp - "${CID}:/workspace"
set +e
docker start -a "${CID}"
TEST_RC=$?
docker cp "${CID}:/workspace/target" "./artifacts" || true
mkdir -p ./artifacts/target/allure-results
if ! ls ./artifacts/target/allure-results/* >/dev/null 2>&1; then
EXTRA_UUID="$(cat /proc/sys/kernel/random/uuid)"
TS_MS="$(( $(date +%s) * 1000 ))"
STATUS="passed"
if [ "${TEST_RC}" -ne 0 ]; then
STATUS="failed"
fi
cat > "./artifacts/target/allure-results/${EXTRA_UUID}-result.json" <<EOF
{
"uuid": "${EXTRA_UUID}",
"historyId": "maven-extra-summary-${BUILD_NUMBER}",
"name": "Maven extra pipeline summary",
"fullName": "pipeline.MavenExtraSummary",
"status": "${STATUS}",
"stage": "finished",
"start": ${TS_MS},
"stop": ${TS_MS},
"labels": [
{"name": "suite", "value": "Pipeline"},
{"name": "package", "value": "pipeline"},
{"name": "testClass", "value": "MavenExtraSummary"},
{"name": "testMethod", "value": "run"}
],
"steps": [],
"parameters": []
}
EOF
fi
{
echo "repo=${EXTRA_REPO_URL}"
echo "ref=${EXTRA_REPO_REF}"
echo "sha=${GIT_SHA}"
echo "maven_goal=${EXTRA_MAVEN_GOAL}"
} > ./artifacts/run-info.txt
{
echo "job=${JOB_NAME}"
echo "build=${BUILD_NUMBER}"
echo "repo.url=${EXTRA_REPO_URL}"
echo "repo.ref=${EXTRA_REPO_REF}"
echo "repo.sha=${GIT_SHA}"
echo "maven.goal=${EXTRA_MAVEN_GOAL}"
} > ./artifacts/target/allure-results/environment.properties
cat > ./artifacts/target/allure-results/executor.json <<EOF
{
"name": "Jenkins",
"type": "jenkins",
"url": "${JENKINS_URL}",
"buildName": "${JOB_NAME} #${BUILD_NUMBER}",
"buildUrl": "${BUILD_URL}",
"reportUrl": "${BUILD_URL}allure",
"buildOrder": ${BUILD_NUMBER}
}
EOF
trap - EXIT INT TERM
docker rm -f "${CID}" || true
exit "${TEST_RC}"
'''
}
}
}
post {
always {
script {
try {
allure commandline: 'allure', includeProperties: false, jdk: '', results: [[path: 'artifacts/target/allure-results']]
} catch (Exception ex) {
echo "Allure publisher unavailable: ${ex.message}"
}
}
junit allowEmptyResults: true, testResults: 'artifacts/target/surefire-reports/*.xml'
archiveArtifacts allowEmptyArchive: true, artifacts: 'artifacts/run-info.txt,artifacts/target/**'
}
}
}