Commit 75e44936 75e449367cd91c27899fd33479abdd4481ed6ab1 by chenjing

更新配置

1 parent a7e0df29
pipeline {
agent any
parameters {
choice(
name: 'DEPLOY_ENV',
choices: ['test', 'uat', 'prod'],
description: '选择部署环境'
)
}
triggers {
cron('0 10 * * *')
}
......@@ -16,7 +8,10 @@ pipeline {
environment {
PYTHON_VERSION = '3.8'
PROJECT_NAME = 'api_test'
DEPLOY_ENV = "${params.DEPLOY_ENV ?: 'test'}"
// 根据 Jenkins Job 名称自动识别环境
// Job 名称格式: APITEST-test / APITEST-uat / APITEST-prod
// 提取最后一个 "-" 后面的部分作为环境名
DEPLOY_ENV = "${env.JOB_NAME.split('-').last()}"
IP_HOST_TEST = 'ai-test.hikoon.com'
IP_HOST_UAT = 'ai-uat.hikoon.com'
IP_HOST_PROD = 'api.hikoon.com'
......@@ -50,15 +45,14 @@ pipeline {
steps {
echo "开始执行API自动化测试 (环境: ${DEPLOY_ENV})..."
script {
def ipHost = 'ai-test.hikoon.com'
def ipHost = env.IP_HOST_TEST
if (env.DEPLOY_ENV == 'uat') {
ipHost = env.IP_HOST_UAT
} else if (env.DEPLOY_ENV == 'prod') {
ipHost = env.IP_HOST_PROD
} else {
ipHost = env.IP_HOST_TEST
}
env.IP_HOST = ipHost
echo "IP_HOST: ${env.IP_HOST}"
}
sh '''
. venv/bin/activate
......@@ -102,31 +96,7 @@ pipeline {
allowEmptyArchive: true,
fingerprint: true
// 发布 HTML 报告到 Jenkins
script {
def reportDir = "reports/${env.DEPLOY_ENV}"
sh "ls -la ${reportDir} 2>/dev/null || echo 'Directory not found'"
def htmlFile = sh(
script: "find ${reportDir} -maxdepth 1 -name '*.html' -type f 2>/dev/null | sort -r | head -1 | xargs basename",
returnStdout: true
).trim()
if (htmlFile) {
echo "找到HTML报告: ${htmlFile}"
publishHTML([
reportDir: reportDir,
reportFiles: htmlFile,
reportName: "Test Report [${env.DEPLOY_ENV}]",
keepAll: true,
alwaysLinkToLastBuild: true,
allowMissing: false
])
echo "HTML报告已发布到Jenkins"
} else {
echo "警告: 未找到HTML报告文件 (路径: ${reportDir})"
}
}
echo "报告已归档到 Jenkins Artifacts"
}
success {
......@@ -138,4 +108,3 @@ pipeline {
}
}
}
......