You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins构建标记失败但自动化测试已通过问题求助

Jenkins中WebdriverIO测试全过但构建失败(Allure钩子报错)

问题详情

在Jenkins创建带参数的构建任务,通过Windows批处理执行WebdriverIO自动化测试。所有测试均显示通过,但Windows批处理步骤将构建标记为失败。控制台输出显示,测试完成后触发的onComplete钩子抛出**"无法生成Allure报告"**错误,尽管后续Jenkins的Allure插件成功生成了报告,构建仍失败。

控制台输出

Started by user *********
Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building in workspace C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task
The recommended git tool is: NONE
No credentials specified
 > git.exe rev-parse --resolve-git-dir C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\.git # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/Valiantsin2021/WebdriverIO-implementation-of-Hardcore-task.git # timeout=10
Fetching upstream changes from https://github.com/Valiantsin2021/WebdriverIO-implementation-of-Hardcore-task.git
 > git.exe --version # timeout=10
 > git --version # 'git version 2.36.1.windows.1'
 > git.exe fetch --tags --force --progress -- https://github.com/Valiantsin2021/WebdriverIO-implementation-of-Hardcore-task.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git.exe rev-parse "refs/remotes/origin/main^{commit}" # timeout=10
Checking out Revision 141c7dd2e797548b9f294f211aa3a4d9529c0804 (refs/remotes/origin/main)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f 141c7dd2e797548b9f294f211aa3a4d9529c0804 # timeout=10
Commit message: "Initial commit"
 > git.exe rev-list --no-walk 141c7dd2e797548b9f294f211aa3a4d9529c0804 # timeout=10
[WebdriverIO-implementation-of-Hardcore-task] $ cmd /c call C:\Windows\TEMP\jenkins5082752157245549591.bat

C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task>npm install 
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

up to date, audited 480 packages in 3s

58 packages are looking for funding
  run `npm fund` for details

14 moderate severity vulnerabilities

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
[WebdriverIO-implementation-of-Hardcore-task] $ cmd /c call C:\Windows\TEMP\jenkins1749588332131908451.bat

C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task>npx cross-env ENV=dev npm run wdio -- --suite smoke 
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> hardcore@1.0.0 wdio
> wdio run wdio.conf.js "--suite" "smoke"


Execution of 2 workers started at 2022-07-19T08:57:48.321Z

[1-0] RUNNING in firefox - C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\tests\SmokeCalculator.test.js
[0-0] RUNNING in chrome - C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\tests\SmokeCalculator.test.js
[0-0] Google
[0-0] YOPmail - 一次性、匿名且免费的电子邮箱地址
[1-0] Google
[1-0] 
[0-0] PASSED in chrome - C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\tests\SmokeCalculator.test.js
[1-0] PASSED in firefox - C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\tests\SmokeCalculator.test.js
2022-07-19T08:58:15.829Z ERROR @wdio/cli:utils: Error in onCompleteHook: Error: Could not generate Allure report
    at Object.onComplete (C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\wdio.conf.js:335:29)
    at C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\node_modules\@wdio\cli\build\utils.js:99:19
    at Array.map (<anonymous>)
    at runOnCompleteHook (C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\node_modules\@wdio\cli\build\utils.js:97:39)
    at Launcher.run (C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\node_modules\@wdio\cli\build\launcher.js:96:75)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

 "spec" Reporter:
------------------------------------------------------------------
[chrome 103.0.5060.114 windows #0-0] Running: chrome (v103.0.5060.114) on windows
[chrome 103.0.5060.114 windows #0-0] Session ID: fe8523ce66d5fa868d0b7d3137574262
[chrome 103.0.5060.114 windows #0-0]
[chrome 103.0.5060.114 windows #0-0] » \tests\SmokeCalculator.test.js
[chrome 103.0.5060.114 windows #0-0] Smoke tests
[chrome 103.0.5060.114 windows #0-0]    ✓ Open google cloud calculator and yopmail.com
[chrome 103.0.5060.114 windows #0-0]
[chrome 103.0.5060.114 windows #0-0] 1 passing (10.3s)
------------------------------------------------------------------
[firefox 102.0.1 windows #1-0] Running: firefox (v102.0.1) on windows
[firefox 102.0.1 windows #1-0] Session ID: e7b8f925-6948-4f01-8344-03170d54c237
[firefox 102.0.1 windows #1-0]
[firefox 102.0.1 windows #1-0] » \tests\SmokeCalculator.test.js
[firefox 102.0.1 windows #1-0] Smoke tests
[firefox 102.0.1 windows #1-0]    ✓ Open google cloud calculator and yopmail.com
[firefox 102.0.1 windows #1-0]
[firefox 102.0.1 windows #1-0] 1 passing (11s)


Spec Files:  2 passed, 2 total (100% completed) in 00:00:27 

Report successfully generated to allure-report
Build step 'Execute Windows batch command' marked build as failure
[WebdriverIO-implementation-of-Hardcore-task] $ C:\ProgramData\Jenkins\.jenkins\tools\ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation\Allure\bin\allure.bat generate C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\allure-results -c -o C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\allure-report
Report successfully generated to C:\ProgramData\Jenkins\.jenkins\workspace\WebdriverIO-implementation-of-Hardcore-task\allure-report
Allure report was successfully generated.
Creating artifact for the build.
Artifact was added to the build.
Recording test results
[Checks API] No suitable checks publisher found.
Finished: FAILURE

相关截图

解决方案

1. 移除WebdriverIO配置中的重复Allure生成逻辑

既然已通过Jenkins Allure插件生成报告,无需在WebdriverIO的onComplete钩子中重复执行。找到wdio.conf.js中第335行的onComplete函数,删除其中生成Allure报告的代码(例如调用allure.generateReport的逻辑)。

2. 捕获钩子中的错误(保留其他逻辑时用)

如果onComplete钩子还有其他必须保留的逻辑,可捕获Allure生成的错误,避免进程返回非0退出码:

onComplete: async function() {
  try {
    // 原有的Allure生成代码或其他逻辑
  } catch (error) {
    console.warn("Allure报告生成失败,将由Jenkins插件处理:", error);
    // 不抛出错误,防止构建失败
  }
}

3. 强制批处理返回成功码(不推荐)

若不想修改代码,可在Jenkins的Windows批处理命令末尾添加exit 0,强制返回成功状态,但这会掩盖其他真实错误:

npx cross-env ENV=dev npm run wdio -- --suite smoke
exit 0

4. 检查Allure版本兼容性

确保@wdio/allure-reporter与Jenkins Allure插件版本兼容,版本差异可能导致报告生成失败。

内容的提问来源于stack exchange,提问作者Valentín_Lu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 05:06:25