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

GitHub Actions生成Allure报告时遇写入权限错误求助

问题:GitHub Actions中Allure报告生成失败(权限拒绝)

技术栈

  • Java 11
  • Maven
  • TestNG
  • Selenium Webdriver
  • Allure Report

本地运行一切正常,但在GitHub Actions执行时无法生成Allure报告,报错如下:

io.qameta.allure.AllureResultsWriteException: Could not write Allure test result container
Error:      at io.qameta.allure.FileSystemResultsWriter.write(FileSystemResultsWriter.java:68)
Error:      at io.qameta.allure.AllureLifecycle.writeTestContainer(AllureLifecycle.java:170)
Error:      at io.qameta.allure.testng.AllureTestNg.onFinish(AllureTestNg.java:195)
Error:      at org.testng.SuiteRunner.invokeListeners(SuiteRunner.java:269)
Error:      at org.testng.SuiteRunner.run(SuiteRunner.java:332)
Error:      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
Error:      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
Error:      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
Error:      at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
Error:      at org.testng.TestNG.runSuites(TestNG.java:1099)
Error:      at org.testng.TestNG.run(TestNG.java:1067)
Error:      at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:295)
Error:      at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84)
Error:      at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:90)
Error:      at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
Error:      at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
Error:      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Error:  Caused by: java.io.FileNotFoundException: allure-results/94d424ca-48b8-454e-b49d-d398a77c5cab-container.json (Permission denied)
Error:      at java.base/java.io.FileOutputStream.open0(Native Method)
Error:      at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
Error:      at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
Error:      at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:187)
Error:      at com.fasterxml.jackson.core.TokenStreamFactory._fileOutputStream(TokenStreamFactory.java:278)
Error:      at com.fasterxml.jackson.core.JsonFactory.createGenerator(JsonFactory.java:1369)
Error:      at com.fasterxml.jackson.databind.ObjectMapper.createGenerator(ObjectMapper.java:1230)
Error:      at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3811)
Error:      at io.qameta.allure.FileSystemResultsWriter.write(FileSystemResultsWriter.java:66)
Error:      ... 16 more 

我的GitHub Actions配置文件如下:

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Stage - Automation

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 11
      uses: actions/setup-java@v3
      with:
        java-version: '11'
        distribution: 'temurin'
        cache: maven
    - name: Install Google Chrome #Using shell script to install Google Chrome
      run:   |
              chmod +x ./scripts/InstallChrome.sh
                          ./scripts/InstallChrome.sh
                          
    - name: Build with Maven
      run: mvn test -P placeOrder_stage -Denv=stage


    - name: Test marketplace action
      uses: simple-elf/allure-report-action@master
      if: always()
      id: allure-report
      with:
        allure_results: allure-results/Reports/*
        gh_pages: gh-pages
        allure_report: allure-report
        allure_history: allure-history


    - name: Deploy report to Github Pages
      if: always()
      uses: peaceiris/actions-gh-pages@v2
      env:
        PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        PUBLISH_BRANCH: gh-pages
        PUBLISH_DIR: allure-history

解决方案

1. 修复目录权限问题

报错核心是Permission denied,说明Maven执行测试时没有权限写入allure-results目录。在Maven测试步骤前添加目录权限设置:

- name: Configure allure-results directory permissions
  run: mkdir -p allure-results && chmod -R 777 allure-results

2. 修正Allure结果路径匹配

配置中allure_results: allure-results/Reports/*,但报错显示测试代码实际往allure-results根目录写结果,路径不匹配。二选一调整:

  • 修改项目中allure.properties配置,指定测试结果输出到allure-results/Reports;
  • 或者将GitHub Actions中allure_results参数改为allure-results,匹配实际输出路径。

3. 更换稳定版Allure报告Action

simple-elf/allure-report-action@master为开发分支,存在不稳定风险,建议更换为稳定版本,比如v1.7.0:

- name: Generate Allure Report
  uses: simple-elf/allure-report-action@v1.7.0
  if: always()
  id: allure-report
  with:
    allure_results: allure-results
    gh_pages: gh-pages
    allure_report: allure-report
    allure_history: allure-history

4. 确认gh-pages分支权限

确保gh-pages分支已创建,且GITHUB_TOKEN拥有该分支的写入权限(私有仓库需额外确认仓库权限配置)。


内容的提问来源于stack exchange,提问作者Helping Hands

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 05:00:44