排查Jenkins构建jar包失败的问题(报错内容:Cannot create resource output)【测试成功】

艺帆风顺 发布于 2025-04-03 23 次阅读


一、问题背景

jenkins运行在docker环境下:

采用Jenkins构建失败,报错如下:

    [INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 06:19 min[INFO] Finished at: 2023-08-29T07:16:06Z[INFO] ------------------------------------------------------------------------Waiting for Jenkins to finish collecting data[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.1.0:resources (default-resources) on project base-core: Cannot create resource output directory: /var/jenkins_home/workspace/yinling-dev-yinling-store/base-core/target/classes -> [Help 1][ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException[ERROR] [ERROR] After correcting the problems, you can resume the build with the command[ERROR] mvn -rf :base-core[JENKINS] Archiving /var/jenkins_home/workspace/yinling-dev-yinling-store/base-core/pom.xml to com.yinling/base-core/1.0-SNAPSHOT/base-core-1.0-SNAPSHOT.pom[JENKINS] Archiving /var/jenkins_home/workspace/yinling-dev-yinling-store/base-boot/pom.xml to com.yinling/base-boot/1.0-SNAPSHOT/base-boot-1.0-SNAPSHOT.pom[JENKINS] Archiving /var/jenkins_home/workspace/yinling-dev-yinling-store/pom.xml to com.yinling/yinling-store/backend/yinling-store-backend.pom[JENKINS] Archiving /var/jenkins_home/workspace/yinling-dev-yinling-store/store-core/pom.xml to com.yinling/store-core/1.0-SNAPSHOT/store-core-1.0-SNAPSHOT.pomchannel stopped推送通知{"markdown":{"content":"【yinling-dev-yinling-store】构建失败!!!😭n >构建用时:6 min 36 secn >[查看控制台](http://192.168.3.66:8888/job/yinling-dev-yinling-store/10/console)"},"msgtype":"markdown"}通知结果{"errcode":0,"errmsg":"ok"}项目运行结果[FAILURE]Finished: FAILURE

    二、问题处理

        由报错日志可知:无法创建目录,怀疑可能是权限问题,随即进入到docker目录下,测试删除,发现依然提示权限不足。

        原因:运行jenkins镜像时,没有采用root权限运行。

        重新修改docker运行容器,加入root权限运行参数如下:

    docker run -u root -d -p 8888:8080 -p 10241:50000 -v /var/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime --name rootjenkins --restart=always --privileged=true rootjenkins

    三、验证修复

        重新执行构建,发现此报错消失。