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_backup</localRepository> 

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

2.增加私服相关配置

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

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<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
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>/home/upload/Repo_backup</localRepository>
  

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
  
  <server>
        <id>bol-release</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
    <server>
        <id>bol-snapshot</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
  
<mirror>
    <id>bolRemote</id>
    <mirrorOf>*</mirrorOf>
    <name>cts</name>
    <url>http://192.168.19.210:8081/nexus/content/groups/public/</url>
</mirror>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>
View Code

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信息了

posted @ 2018-04-11 13:39  三国梦回  阅读(5773)  评论(0编辑  收藏  举报