TeamCity 和 Nexus 的使用

来源:互联网 发布:截取串口数据代码 编辑:程序博客网 时间:2024/05/17 15:03

参考:http://www.jianshu.com/p/255a484555d9

TeamCity 安装部署(Linux 环境)

  • 在我讲之前,如果你英文还可以,就到官网这里看下:
  • Installation Quick Start
  • 安装环境要求:
    • JDK 1.7 以上,如果你要使用的是 2016 最新的 TeamCity 9.1 的话,JDK 官网推荐的 1.8
  • 安装包下载:https://www.jetbrains.com/teamcity/download/#section=linux-version
  • 开始安装(eg:TeamCity-9.1.6.tar.gz):
    • 解压压缩包(解压速度有点慢):tar zxf TeamCity-9.1.6.tar.gz
    • 解压完的目录结构讲解:https://confluence.jetbrains.com/display/TCD9/TeamCity+Home+Directory
    • 下载的 tar.gz 的本质是已经里面捆绑了一个 Tomcat,所以如果你会 Tomcat 的话,有些东西你可以自己改的。
    • 按我个人习惯,把解压缩的目录放在 usr 目录下:mv TeamCity/ /usr/program/
    • 进入解压目录:cd /usr/program/TeamCity/
    • 启动程序:/usr/program/TeamCity/bin/runAll.sh start
    • 停止程序:/usr/program/TeamCity/bin/runAll.sh stop
    • 启动需要点时间,最好能给它一两分钟吧

首次进入

  • 假设我们已经启动了 TeamCity
  • 访问(TeamCity 默认端口是:8111):http://192.168.1.113:8111/
  • 如果访问不了,请先关闭防火墙:service iptables stop
  • 你也可以选择把端口加入白名单中:
    • sudo iptables -I INPUT -p tcp -m tcp --dport 8111 -j ACCEPT
    • sudo /etc/rc.d/init.d/iptables save
    • sudo service iptables restart
  • 如果你要改变端口,找到下面这个 8111 位置:vim /usr/program/TeamCity/conf/server.xml
<Connector port="8111" ...
  • 在假设你已经可以访问的情况,我们开始进入 TeamCity 的设置向导:

  • TeamCity 向导
    • 如上图英文所示,TeamCity 的一些软件安装的配置、服务的配置默认都会放在:/root/.BuildServer
    • 如果你要了解更多 TeamCity Data Directory 目录,你可以看:https://confluence.jetbrains.com/display/TCD9/TeamCity+Data+Directory

  • TeamCity 向导
    • 如上图英文所示,TeamCity 的一些构建历史、用户信息、构建结果等这类数据是需要放在关系型数据库上的,而默认它给我们内置了一个。
    • 如果你要了解更多 TeamCity External Database,你可以看:https://confluence.jetbrains.com/display/TCD9/Setting+up+an+External+Database
    • 首次使用,官网是建议使用默认的:Internal(HSQLDB),这样我们无需在一开始使用的就考虑数据库迁移或安装的问题,我们只要好好感受 TeamCity 给我们的,等我们决定要使用了,后续再更换数据也是可以的。但是内置的有一个注意点:'TeamCity with the native MSSQL external database driver is not compatible with Oracle Java 6 Update 29, due to a bug in Java itself. You can use earlier or later versions of Oracle Java.'
    • 假设我们就选 Internal(HSQLDB) ,则在创建初始化数据库的过程稍微需要点时间,我这边是几分钟。

  • TeamCity 向导
    • 如上图所示,接受下协议

  • TeamCity 向导
    • 如上图所示,我们要创建一个顶级管理员账号,我个人习惯测试的账号是:admin123456

  • TeamCity 向导
    • 如上图所示,安装完首次进来地址:http://192.168.1.113:8111/profile.html?tab=userGeneralSettings
    • 我们可以完善一些管理员信息和基础配置信息,这些配置不配置都无所谓了,只是完善了可以更加好用而已
    • 如果你有 SMTP 的邮箱,你可以来这里开启邮件通知功能:http://192.168.1.113:8111/admin/admin.html?item=email
    • 如果你要开启通知功能那肯定下一步就是考虑通知内容的模板要如何设定:https://confluence.jetbrains.com/display/TCD9//Customizing+Notifications
    • 模板存放路径在:/root/.BuildServer/config/_notifications,用的是 FreeMarker 的语法

项目的构建、管理

  • 建议可以看下官网:https://confluence.jetbrains.com/display/TCD9/Configure+and+Run+Your+First+Build
  • 现在让我们开始创建一个项目进行构建
  • 项目管理地址:http://192.168.1.113:8111/admin/admin.html?item=projects
  • 假设我现在有一个项目的结构是这样的:
- Youshop-Parent,输出是 pom    - Youshop-manage,输出是 pom        - Youshop-pojo,输出 jar
  • 我们现在以 Youshop-pojo 为例,让它自动构建并发布到 Nexus 中,其他项目道理是一样的,这里就不多说。

  • TeamCity 向导
  • 如上图,由于目前只要是公司的项目都应该是在版本控制的,所以这里我们选择:Create project from URL

  • TeamCity 向导
  • 如上图,我们可以看出 TeamCity 也支持 HTTP、SVN、Git 等链接方式。

  • TeamCity 向导
  • 输入你项目托管商的账号密码,我这里用的是 oschina 的。

  • TeamCity 向导
  • 账号、密码验证通过,现在可以给这个项目配置一个项目基本信息。

  • TeamCity 向导
  • 在从版本控制中下载文件和扫描文件

  • TeamCity 向导
  • TeamCity 自动扫描到我是用 Maven 构建的项目,所以把 POM 文件找出来了,如果你一个项目有多种构建方式,有对应的配置文件的话,这里都会显示出来的。
  • 我们勾选 Maven 前面的复选框,点击:Use Selected

  • TeamCity 向导
  • 由于我们的目标是构建完自动发布到 Nexus,所以我们的 Maven Goals 应该是:clean install deploy,这里我们应该点击:Edit,进行编辑。
  • 如果你不懂 Maven Goals,那你需要学习下,这个很重要。
    • 官网:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

  • TeamCity 向导
    • 如上图,这台服务器必须装有 Maven、JDK
    • 如上图,Goals 我们的目标是 clean install deploy
    • 如上图,Maven Home 我建议是自己自定义路径,这样肯定不会有问题。所以你服务器上的 Maven 安装路径是什么你就在这里填写上去。Maven 目前支持的最高版本是:3.2.5
      • 下载 Maven 3.2.5:http://archive.apache.org/dist/maven/maven-3/3.2.5/binaries/
    • 如上图,Java Parameters 我建议也是自己自定义路径,别选择其他选项。

  • TeamCity 向导
    • 如上图,点击 run,开始手动构建该项目

  • TeamCity 向导
    • 如上图,我们看到简略的构建日志

  • TeamCity 向导

  • TeamCity 向导
    • 如上 2 张图,我们看到详细的构建内容

  • TeamCity 向导
    • 如上图,当我们版本控制中有提交的时候,TeamCity 会识别到记录

  • TeamCity 向导
    • 如上图,我们可以看到提交的 Commit Message 信息。
    • 如上图,右边红圈的三个按钮是用来处理这次提交的,常用的是第一次按钮,点击对此次版本进行构建

  • TeamCity 向导
    • 如上图,如果你要看所有的提交记录,可以在 Change Log 看到并且指定版本构建

  • TeamCity 向导
    • 如上图,如果在你不想要这个项目的时候可以进行删除

  • TeamCity 向导
    • 如上图,因为 Goals 里面有 deploy 命令,所以构建完成会发布到 Nexus 中,这样团队的人就可以用到最新的代码了

  • TeamCity 向导
    • 如上 gif 图演示,项目常去的几个配置地方就是这样些了

配置自动构建触发行为

  • 官网提供的触发行为有:https://confluence.jetbrains.com/display/TCD9/Configuring+Build+Triggers
  • 下面我们举例说常见的:VCS TriggerSchedule Trigger

  • TeamCity 向导
    • 如上图,点击 Add new trigger 添加触发器

  • TeamCity 向导
    • 如上图,常见的触发器就这些了

  • TeamCity 向导
    • 如上图,配置好 VCS Trigger 效果是,当我们有代码提交的时候,TeamCity 检查到新版本之后自动构建,这个最常用





参考:http://blog.csdn.net/johnstrive/article/details/49894195

STEP1下载安装

目前免费版是2.x,所以下载个免费版
https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.13.0-01-bundle.tar.gz

[root@localhost ~]# tar -zxvf nexus-2.13.0-01-bundle.tar.gz[root@localhost download]# lltotal 70780drwxr-xr-x. 8 1001 1001     4096 Apr 12 16:11 nexus-2.13.0-01   #nexus 服务-rw-r--r--. 1 root root 72466664 Jun 23 08:28 nexus-2.13.0-01-bundle.tar.gzdrwxr-xr-x. 3 1001 1001     4096 Apr 12 16:21 sonatype-work   #私有库目录

STEP2 配置

nexus.properties配置文件

[root@localhost conf]# pwd/root/download/nexus-2.13.0-01/conf[root@localhost conf]# vim nexus.properties # Jetty sectionapplication-port=8081  #默认访问端口,可以修改为自己需要的端口,并加入到iptables链application-host=0.0.0.0 nexus-webapp=${bundleBasedir}/nexusnexus-webapp-context-path=/nexus# Nexus sectionnexus-work=${bundleBasedir}/../sonatype-work/nexusruntime=${bundleBasedir}/nexus/WEB-INF

nexus执行文件

[root@localhost conf]# vi /root/download/nexus-2.13.0-01/bin/nexus#RUN_AS_USER=改为:RUN_AS_USER=root

防火墙中打开 8081 端口

# vi /etc/sysconfig/iptables添加:-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT 保存后重启防火墙# service iptables restart

STEP3 启动 nexus

[root@localhost conf]# /root/download/nexus-2.13.0-01/bin/nexus start **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Starting Nexus OSS...Started Nexus OSS.

关于如何使用nexus

网上资料很多,参考几篇就搞定了。
http://www.cnblogs.com/luotaoyeah/p/3791966.html
http://blog.csdn.net/ichsonx/article/details/14642897

其他关键配置项

切换中央仓库为阿里云仓库,修复索引
这里写图片描述
加入central到public仓库地址,这样才能正常下载到依赖
这里写图片描述

项目配置

Maven配置

首先需要配置是的maven的setting.xml文件,我直接全部放上来,具体看注释

<?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"><!--设置自己的maven本地仓库--><localRepository>/Users/jm/Documents/work/mrepository</localRepository>    <pluginGroups/>    <proxies/>    <servers>       <server>         <id>nexus-rs</id> <!--这个ID要与下面的repository中的ID一致-->        <username>deployment</username> <!--nexus中配置的用户名密码-->        <password>xiaoshoujia123</password>       </server>       <server>         <id>nexus-snapshots</id>         <username>deployment</username>         <password>xiaoshoujia123</password>       </server>     </servers>    <mirrors><!--从nexus下载依赖地址-->        <mirror>            <id>nexus-public</id>            <mirrorOf>central</mirrorOf>            <name>central repository</name>            <url>http://192.168.199.146:8081/nexus/content/groups/public/</url>        </mirror>    </mirrors>    <profiles>        <profile>             <id>nexus</id>             <repositories>                 <repository>                     <id>nexus-rs</id> <!--正式仓库id-->                    <!--name随便-->                    <name>Nexus Release Snapshot Repository</name>                     <!--地址是nexus中repository(Releases/Snapshots)中对应的地址-->                    <url>http://192.168.199.146:8081/nexus/content/repositories/releases</url>                    <releases>                        <enabled>true</enabled>                    </releases>                     <snapshots>                        <enabled>true</enabled>                    </snapshots>                 </repository>                <repository>                    <id>nexus-snapshots</id>                    <url>http://192.168.199.146:8081/nexus/content/repositories/snapshots</url>                    <releases><enabled>true</enabled></releases>                    <snapshots><enabled>true</enabled></snapshots>                </repository>            </repositories>             <pluginRepositories> <!--插件仓库地址,各节点的含义和上面是一样的-->                <pluginRepository>                     <id>nexus-rs</id>                     <name>Nexus Release Snapshot Repository</name>                     <url>http://192.168.199.146:8081/nexus/content/repositories/releases</url>                    <releases>                        <enabled>true</enabled>                    </releases>                     <snapshots>                        <enabled>true</enabled>                    </snapshots>                </pluginRepository>                 <pluginRepository>                     <id>nexus-snapshots</id>                    <url>http://192.168.199.146:8081/nexus/content/repositories/snapshots</url>                    <releases><enabled>true</enabled></releases>                    <snapshots><enabled>true</enabled></snapshots>                </pluginRepository>             </pluginRepositories>         </profile>    <!--激活配置-->    <activeProfiles>        <activeProfile>nexus</activeProfile> <!--profile下的id-->    </activeProfiles></settings>
  • 64
  • 65

pom.xml配置

根节点project中增加

        <distributionManagement>         <!-- 两个ID必须与 setting.xml中的<server><id>nexus-rs</id></server>保持一致-->            <repository>                <id>nexus-rs</id>                <name>Nexus Release Repository</name>                <url>http://192.168.199.146:8081/nexus/content/repositories/releases/</url>            </repository>            <snapshotRepository>                <id>nexus-snapshots</id>                <name>Nexus Snapshot Repository</name>                <url>http://192.168.199.146:8081/nexus/content/repositories/snapshots/</url>            </snapshotRepository>        </distributionManagement>




原创粉丝点击