linux

Linux下Jenkins如何测试

小樊
44
2025-12-04 09:00:31
栏目: 智能运维

Linux下Jenkins测试实操指南

一 环境准备与安装

二 测试类型与示例流水线

测试类型 前置与环境 关键命令或插件 报告与归档
单元测试(Java + Maven) 安装 Maven,项目遵循 Maven 结构 mvn test JUnit 报告(target/surefire-reports/*.xml),使用 “Publish JUnit test result report” 归档
接口/性能(JMeter) 安装 JMeter 并配置 JMETER_HOME jmeter -n -t script.jmx -l result.jtl -j run.log 使用 Performance Plugin 展示聚合报告;或用 HTML Publisher 发布 HTML 报告
UI 自动化(Selenium + Allure) 安装 pytestAllure 命令行 pytest … --alluredir=allure_results Allure 报告(需配置 Allure Commandline 工具路径)
pipeline {
  agent any
  environment {
    JMETER_HOME = '/opt/jmeter/apache-jmeter-5.4.3'
    PATH = "${JMETER_HOME}/bin:${env.PATH}"
  }
  stages {
    stage('Checkout') { steps { git 'https://github.com/example/perf-test.git' } }
    stage('Run JMeter') {
      steps {
        sh 'jmeter -n -t ${WORKSPACE}/script/test.jmx -l ${WORKSPACE}/result.jtl -j ${WORKSPACE}/run.log'
      }
    }
  }
  post {
    always {
      junit '**/result.jtl'                     // 若脚本生成JUnit兼容XML
      publishHTML(target: [reportDir: '**/html', reportFiles: 'index.html', reportName: 'JMeter HTML Report'])
      perfReport '**/result.jtl'                // Performance Plugin
    }
  }
}
pipeline {
  agent any
  tools { nodejs 'node-18' } // 如用npm/webdriver-manager
  stages {
    stage('Checkout') { steps { git 'https://github.com/example/ui-test.git' } }
    stage('Install deps') { steps { sh 'pip install -r requirements.txt' } }
    stage('Run UI Tests') {
      steps { sh 'pytest tests/ --alluredir=allure_results --clean-alluredir' }
    }
  }
  post {
    always { allure includeProperties: false, jdk: '', results: [[path: 'allure_results']] }
  }
}

三 触发与报告查看

四 常见问题与排查

0
看了该问题的人还看了