122 lines
4.1 KiB
Groovy
122 lines
4.1 KiB
Groovy
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} api"
|
|
currentBuild.description =
|
|
"by=${env.RUN_TRIGGER_NAME}; repo=${params.QA_REPO_URL}; ref=${params.QA_REPO_REF}"
|
|
}
|
|
}
|
|
}
|
|
stage('Run API Tests In Docker') {
|
|
steps {
|
|
sh '''
|
|
set -eux
|
|
git config --global --add safe.directory '*' || true
|
|
rm -rf ./sources
|
|
git clone "${QA_REPO_URL}" ./sources
|
|
git -C ./sources checkout "${QA_REPO_REF}"
|
|
GIT_SHA="$(git -C ./sources rev-parse --short HEAD)"
|
|
|
|
rm -rf ./artifacts
|
|
mkdir -p ./artifacts
|
|
{
|
|
echo "job=${JOB_NAME}"
|
|
echo "build=${BUILD_NUMBER}"
|
|
echo "trigger_user=${RUN_TRIGGER_USER}"
|
|
echo "trigger_name=${RUN_TRIGGER_NAME}"
|
|
echo "qa_repo_url=${QA_REPO_URL}"
|
|
echo "qa_repo_ref=${QA_REPO_REF}"
|
|
echo "qa_repo_sha=${GIT_SHA}"
|
|
echo "timestamp_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
} > ./artifacts/run-info.txt
|
|
|
|
CID="$(docker create localhost:5005/otus/test-api:1.0.0 bash -lc "set -e; cd /workspace; mvn -f citrus-tests/pom.xml -Dallure.results.directory=target/allure-results test")"
|
|
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/citrus-tests/target" "./artifacts/citrus-target" || true
|
|
mkdir -p ./artifacts/citrus-target/allure-results
|
|
if ! ls ./artifacts/citrus-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/citrus-target/allure-results/${EXTRA_UUID}-result.json" <<EOF
|
|
{
|
|
"uuid": "${EXTRA_UUID}",
|
|
"historyId": "api-citrus-summary-${BUILD_NUMBER}",
|
|
"name": "API Citrus pipeline summary",
|
|
"fullName": "pipeline.ApiCitrusSummary",
|
|
"status": "${STATUS}",
|
|
"stage": "finished",
|
|
"start": ${TS_MS},
|
|
"stop": ${TS_MS},
|
|
"labels": [
|
|
{"name": "suite", "value": "Pipeline"},
|
|
{"name": "package", "value": "pipeline"},
|
|
{"name": "testClass", "value": "ApiCitrusSummary"},
|
|
{"name": "testMethod", "value": "run"}
|
|
],
|
|
"steps": [],
|
|
"parameters": []
|
|
}
|
|
EOF
|
|
fi
|
|
{
|
|
echo "job=${JOB_NAME}"
|
|
echo "build=${BUILD_NUMBER}"
|
|
echo "repo.url=${QA_REPO_URL}"
|
|
echo "repo.ref=${QA_REPO_REF}"
|
|
echo "repo.sha=${GIT_SHA}"
|
|
} > ./artifacts/citrus-target/allure-results/environment.properties
|
|
cat > ./artifacts/citrus-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/citrus-target/allure-results']]
|
|
} catch (Exception ex) {
|
|
echo "Allure publisher unavailable: ${ex.message}"
|
|
}
|
|
}
|
|
junit allowEmptyResults: true, testResults: 'artifacts/citrus-target/surefire-reports/*.xml'
|
|
archiveArtifacts allowEmptyArchive: true, artifacts: 'artifacts/run-info.txt,artifacts/citrus-target/**'
|
|
}
|
|
}
|
|
}
|