一:背景交代
這兩天組長讓我這邊搭一個持續集成環境。梳理了需求后,因為我們的項目都是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>
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信息了