jenkins配置findbugs失败---不要随便忽略警告!一个因为文件所有权引发的血案


一:背景交代

这两天组长让我这边搭一个持续集成环境。梳理了需求后,因为我们的项目都是maven项目,所以我选择了jenkins+外置maven(区别于直接从jenkins里面安装)的方案。(centos 7)

jenkins的安装先不细说,maven的安装也是直接参考了https://maven.apache.org/install.html。

maven信息:

[root@pas upload]# mvn -v
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: /usr/local/apache-maven-3.5.3
Java version: 1.8.0_161, vendor: Oracle Corporation
Java home: /usr/local/jdk1.8.0_161/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"

接下来,说下我的maven的配置。

我修改了maven安装目录下的conf下的settings.xml(/usr/local/apache-maven-3.5.3/conf/settings.xml)

1.修改仓库位置

  <localRepository>/home/upload/Repo_backuplocalRepository> 

 由于我的windows服务器上已经有了本地仓库,所以直接压缩成zip后上传到了centos上,解压到了 /home/upload/Repo_backup。

2.增加私服相关配置

<?xml version="1.0" encoding="UTF-8"?>




<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  
  <localRepository>/home/upload/Repo_backuplocalRepository>
  

  

  

  
  <pluginGroups>
    
  pluginGroups>

  
  <proxies>
    
  proxies>

  
  <servers>
  
  <server>
        <id>bol-releaseid>
        <username>adminusername>
        <password>admin123password>
    server>
    <server>
        <id>bol-snapshotid>
        <username>adminusername>
        <password>admin123password>
    server>
    

    
  servers>

  
  <mirrors>
  
<mirror>
    <id>bolRemoteid>
    <mirrorOf>*mirrorOf>
    <name>ctsname>
    <url>http://192.168.19.210:8081/nexus/content/groups/public/url>
mirror>
    
  mirrors>

  
  <profiles>
    <profile>
      <id>nexusid>
      
      
      <repositories>
        <repository>
          <id>centralid>
          <url>http://centralurl>
          <releases><enabled>trueenabled>releases>
          <snapshots><enabled>trueenabled>snapshots>
        repository>
      repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>centralid>
          <url>http://centralurl>
          <releases><enabled>trueenabled>releases>
          <snapshots><enabled>trueenabled>snapshots>
        pluginRepository>
      pluginRepositories>
    profile>
  profiles>
  <activeProfiles>
    <activeProfile>nexusactiveProfile>
  activeProfiles>
settings>

3.jenkins安装maven插件并新建maven项目

系统管理--》管理插件--》可选插件--》Maven Integration plugin

勾选后点直接安装,等待安装完成后,新建任务中就会出现下图所示的“构建一个maven项目”的选项:

4.项目配置

配置svn

配置maven goal:

然后点保存,启动立即构建后,works well。

二:问题出现

我准备给这个项目加上findbugs来进行代码分析检查。

步骤很简单,我只是在build中增加了findbugs:findbugs:

ok。以上配置完成,开始构建。

然而构建总是报错,提示如下:

[ERROR] Failed to execute goal org.codehaus.mojo:findbugs-maven-plugin:3.0.5:findbugs (default-cli) on project my-app: Execution default-cli of goal org.codehaus.mojo:findbugs-maven-plugin:3.0.5:findbugs failed: Plugin org.codehaus.mojo:findbugs-maven-plugin:3.0.5 or one of its dependencies could not be resolved: Failed to collect dependencies at org.codehaus.mojo:findbugs-maven-plugin:jar:3.0.5 -> org.apache.maven.reporting:maven-reporting-impl:jar:3.0.0 -> org.apache.maven.doxia:doxia-core:jar:1.7 -> xmlunit:xmlunit:jar:1.5: Failed to read artifact descriptor for xmlunit:xmlunit:jar:1.5: Could not transfer artifact xmlunit:xmlunit:pom:1.5 from/to central (https://repo.maven.apache.org/maven2): /home/upload/Repo_backup/xmlunit/xmlunit/1.5/xmlunit-1.5.pom.part.lock (没有那个文件或目录) -> [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/PluginResolutionException

排除过程:
1.我感觉是因为私服有问题,可能私服中不存在该版本的findbugs插件的依赖,导致下载失败。

首先尝试了将maven的settings.xml中的私服配置去掉,然后重新构建,依然有问题。后来发现项目的pom中配置了私服,因此换了个项目(该项目的pom中没有用到私服中的包),重新构建。

2.问题依旧。这次依旧没有了私服,难道是maven中央仓库的问题,仔细去找了maven库,依赖都存在啊。
3.难道是下载不下来么? 尝试了去本地库中将
findbugs-maven-plugin目录删除掉,希望能重新下载下来,构建却依然报错。
3.既然下载有问题,于是又从windows开发机器上将
findbugs-maven-plugin拷贝到centos上后,重新构建,依然报错。

后来(很后很后,昨天一下午都没搞定,所以是后到了今天上午)发现:
编译过程中有些警告:

我就想:为啥会创建这些东西失败呢?感觉没道理啊。

没有权限吗?但如下图所示,我早就将该目录下的文件所有者改成了jenkins。

那?难道是?

注意上图,刚开始的时候,我是从windows上上传了Repo_backup.zip,然后解压缩到Repo_backup。因为是root用户操作的,所以
理所当然,Repo_backup的用户和用户组是root
而这会导致jenkins在执行时,所用的jenkins用户根本无法写入Repo_backup目录。所以才有了诸多的创建失败。

创建失败,为啥没报错呢?因为那些jar包,在我本地的windows上是有的,但是jenkins重新去maven中央仓库更新时,看到本地仓库有了,但是应该还是会更新下.lastUpdated之类的文件
来刷新时间戳吧(我猜的)。

总之,当我将Repo_backup的用户和组修改为jenkins后,findbugs终于正常了。


三:结语

所以,其实最后呢,还是因为自己的马虎大意或者说对linux还是不够懂,也可以说:已经习惯性地忽略警告信息导致了这次的大坑。

以后,大概不会再随便忽略warning信息了