jenkins

 

使用jekins自动构建部署java maven目(jdk1.7+tomcat7.0+jenkins2.19.3

1.下载jenkins

地址:https://jenkins.io/index.html

本人下载了2.19.3版本的war包:jenkins.war

 

2.安装jenkins

 拷贝jenkins.wartomcatwebapps文件夹下,如果tomcat是启动的,jenkins项目会自动解压启动的,如果tomcat是停止的,需要启动tomcat服务,进入bin文件夹,linux环境下执行./startup.sh即可启动服务,windows下双击startup.bat即可。

然后,访问地址:http://192.168.17.155:8080/jenkins,具体ip为你部署的机器的ip, 看到如下界面,那么恭喜你,jenkins启动了。

为了安全,jenkins要求你填写初始化密码,密码在提示的文件里面,找到该文件,拷贝出密码,填写在下面的文本框中,点击Continue即可。(如果windows下,tomcat的控制台也能看到提示的密码,linux下查看tomcatcatalina.out这个日志文件中也能找到此密码。)

选择安装方式,选择第一种即可,点击一下,进入如下界面

各种插件安装完后,开始设置账户信息,以后用此账户登录jenkins

然后进入首页

 

3.安装插件

上述默认安装的插件还不够

依次点击系统管理->插件管理->可选插件->过滤搜索框中查找如下插件:

MavenIntegration plugin

SSHplugin

Deploy to containerPlugin

 

4.新建构建任务

 找到代码管理的地方,如果是svn管理的,请选择Subversion,填入项目地址和账号信息,如果是git,填写git信息即可

构建触发器,去掉所有勾选,采用手动点击触发即可

上述信息提示配置一下maven的安装路径,我们照做即可,顺便配置好jdk路径

maven构建命令配置

 

 部署配置

tomcat用户在conf/tomcat-user.xml里面配置即可,下面给出配置

<tomcat-users>   <role rolename="manager-gui" />  <role rolename="manager-status" />  <role rolename="manager-jmx" />  <role rolename="manager-script"/> <role rolename="admin-gui"/> <role rolename="admin-script"/>  <user username="tomcat" password="tomcat" roles="manager-gui,manager-status,manager-jmx,manager-script,admin-gui,admin-script"/> </tomcat-users>

保存配置

 

5.构建

点击导航jenkins -> My Views-> 点击study项目->立即构建

如果发现界面卡死,可能是jdk内存溢出,出现如下

设置一下tomcatjdk参数即可

windowscatalina.bat 文件里添加如下参数(添加到文件开头):

setJAVA_OPTS=-server -XX:PermSize=512M -XX:MaxPermSize=2048M -Xms512M -Xmx2048M-XX:MaxNewSize=512M

linuxcatalina.sh文件里添加如下参数(添加到文件开头):

JAVA_OPTS="-server-XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M-XX:MaxNewSize=256m"

是否添加成功,可以使用 jps -v 命令查看(windows和linux下均可)

 

 

重新启动tomcat,重新点击构建即可,ConsoleOutput里可以看到整个构建的过程,出现如下图就表示整个构建部署成功了

 

6.附上shell脚步部署方式,更加灵活些(jenkins和服务器必须都是linux机器)

 

思路就是,执行远程脚本关闭tomcat,然后执行本地脚本拷贝文件到远程,再执行远程脚本启动tomcat服务。上述scp命令传输文件不用密码,必须配置一下ssh的密钥对,配置方式如下:

 

这里假设主机A192.168.100.3)用来获到主机B192.168.100.4)的文件。

在主机A上执行如下命令来生成配对密钥:
ssh-keygen-t rsa

遇到提示回车默认即可,公钥被存到用户目录下.ssh目录,比如root存放在:

/root/.ssh/id_rsa.pub

.ssh 目录中的id_rsa.pub 文件复制到主机B ~/.ssh/ 目录中,并改名为 authorized_keys
到主机A中执行命令和主机B建立信任,例(假设主机BIP:192.168.100.4):

scp~/.ssh/id_rsa.pub 192.168.100.4:/root/.ssh/authorized_keys

下面就可以用scpssh命令不需要密码来获取主机B的文件了
ssh 192.168.100.4
回车就不需要密码了。

 

如果机器B添加多个的机器的公需要在authorized_keys中追加公钥内容,命令如下:

cat id_rsa.pub >>/root/.ssh/authorized_keys

 

 ============================================================================================

Jenkins 操作文档

1.  部署操作

登录

 

项目列表

 

 

构建部署

控制台输出

构建部署结果

2.  部署配置

新建

配置

 

 

 

 

 

 

 

 

 

 

 

项目名称

必须唯一

丢弃旧的构建

控制磁盘空间消耗

启用项目安全

控制登录用户权限

 

 

 

 

参数化构建过程

 

 

 

 

 

 

 

 

 

 

 

 

源码管理
绝对地址填写方式

参数化地址填写方式

(标红的可以忽略,实际部署自动添加参数)

Checkout选项

分布式部署

勾选后,此项目在指定的节点编译,主要用于多机房部署

不勾选则在Jenkins master编译

 

构建脚本

Shell脚本,根据项目要求不同填写脚本,这里是直接打tar包

 

 

 

 

 

构建后操作
登录信息

认证测试

 

 

 

 

 

 

 

 

 

 

 

 

 

部署配置

 

部署操作需要捕捉异常,否则Jenkins自动提示Success

 

if [ "$?" != "0" ];then

  exit 1

fi

部署后邮件通知

 

 

 

 

 

 

 

 

 

 

3.  部署状态

任务历史,蓝色球状图标标准构建成功,其他颜色表示有异常

 

 

 

4.  Jenkins系统管理

 

 

 

 

 

 

 

 

 

Git

执行文件

Git账号

Maven

Jenkins根目录

 

SSHD Port

邮件通知

SSH Server

部署配置中需要引用的

GitLab

 

5.  Jenkins安全设置

启用安全

访问控制

项目矩阵授权策略

Admin所有权限都给

匿名账户没有任何权限

其他账户只有Read权限

 

 

 

 

 

 

 

6.  Jenkins管理插件

已安装插件

        

Ant Plugin

This plugin adds Apache Ant support toJenkins.            

        

conditional-buildstep

A buildstep wrapping any number of otherbuildsteps, controlling their execution based on a defined condition (e.g.BuildParameter).                  

        

Copy To Slave Plugin

This plugin allows copying files locatedsomewhere on the master node into the jobs' workspaces, whether their buildstake place on the master node or on slave nodes.

 

Credentials Plugin

This plugin allows you to store credentialsin Jenkins.

        

CVS Plug-in

Integrates Jenkins with CVS version controlsystem using a modified version of the Netbeans cvsclient.

        

Environment Injector Plugin

This plugin makes it possible to set anenvironment for the builds.

 

External Monitor Job Type Plugin

Adds the ability to monitor the result ofexternally executed jobs.

        

Git Client Plugin

Shared library plugin for other Git relatedJenkins plugins.

        

Git Plugin

This plugin integrates GIT with Jenkins.

        

GitLab Plugin

This plugin integrates GitLab to Jenkins byfaking a GitLab CI Server.            

        

Hudson SCP publisher plugin

This plugin uploads build artifacts torepository sites using SCP (SSH) protocol.            

        

Javadoc Plugin

This plugin adds Javadoc support toJenkins.

        

JUnit Plugin

Allows JUnit-format test results to bepublished.

        

LDAP Plugin

Security realm based on LDAP authentication.

        

Mailer Plugin

This plugin allows you to configure emailnotifications. This is a break-out of the original core based email component.

        

MapDB API Plugin

This plugin provides a shared dependency onthe MapDB library so that other plugins can co-operate when using this library.                  

        

Matrix Authorization Strategy Plugin

Offers matrix-based security authorizationstrategies (global and per-project).  

        

Matrix Project Plugin

Multi-configuration (matrix) project type.

        

Maven Project Plugin

Jenkins plugin for building Maven 2/3 jobsvia a special project type.

        

Multijob Plugin

This plugin is a MultiJob plugin.                         

        

OWASP Markup Formatter Plugin

Uses the OWASP Java HTML Sanitizer to allowsafe-seeming HTML markup to be entered in project descriptions and the like.

        

PAM Authentication plugin

Adds Unix Pluggable Authentication Module(PAM) support to Jenkins.

        

Parameterized Trigger plugin

This plugin lets you trigger new buildswhen your build has completed, with various ways of specifying parameters forthe new build.                  

        

Publish Over SSH

Send build artifacts over SSH           

        

Role-based Authorization Strategy

Enables authorization using a role-basedstrategy.                 

        

Run Condition Plugin

Core conditions to select whether toexecute a build step or publisher. Used by the [Flexible Publish Plugin] andthe [Conditional BuildStep Plugin].             

        

SCM API Plugin

This plugin provides a new enhanced API forinteracting with SCM systems.       

        

Slave Prerequisites plugin

Run a script on slave node before startingjob on it to check some prerequisites.                 

        

Slave SetupPlugin

This plugin prepares slaves for buildexecution by letting you copy files and execute scripts before the slave getsused.  

        

slave-status

Visit a url like http://myslave:3141 to seean XML document giving the slave's status. Use automated tools like curl ornagios to check this data periodically, if you want to.   

        

SSH Credentials Plugin

This plugin allows you to store SSHcredentials in Jenkins.

        

SSH Slaves plugin

This plugin allows you to manage slavesrunning on \*nix machines over SSH.

        

Subversion Plug-in

This plugin adds the Subversion support(via SVNKit) to Jenkins.  

        

Token Macro Plugin

This plug-in adds reusable macro expansioncapability for other plug-ins to use.          

        

Translation Assistance plugin

This plugin adds an additional dialog boxin every page, which enables people to contribute localizations for themessages they are seeing in the current page.    

        

Windows Slaves Plugin

Allows you to connect to Windows machinesand start slave agents on them.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7.  Jenkins管理节点

用于跨机房分布式部署

 

防御性节点检测

新建节点

配置从节点

 

 

具体配置

 

8.  Jenkins用户管理

新建用户

9.  Jenkins Credentials

Svn账户

新建账户

更新账户


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值