Jenkins+git+maven持续集成
程序员文章站
2022-05-14 20:42:46
...
Jenkins持续集成
Jenkins部署:
1.解压安装jdk、tomcat
5.源码安装git、maven,设置环境变量
export JAVA_HOME=/usr/local/jdk
export MAVEN_HOME=/usr/local/maven
export GIT_HOME=/usr/local/git
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$GIT_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
6.查看版本:#mvn -v
#git --version
2.清空/weapps,将Jenkins.war放入目录下
3.修改字符集 :#vim /usr/local/apache-tomcat-7.0.30/conf/server.xml
<Connector port="8080" URIEncoding="UTF-8" />
3.启动Tomcat,Jenkins地址:http://ip:8080/jenkins
6.使用gitlab源安装gitlab-ce:
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
#yum -y install gitlab-ce
7.修改地址:#vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab-test.com'
unicorn['listen'] = '192.168.12.199'
unicorn['port'] = 8801
添加本地解析:vim /etc/hosts
8.重新配置:#gitlab-ctl reconfigure
9.重启: #gitlab-ctl start/stop/restart
10.登录gitlab: http://ip
4.下载Jenkins插件:Gitlab Hook、Build Authorization Token Root、Publish Over SSH、Gitlab Authentication、Gitlab
11.登录Jenkins添加用户,jdk地址、git地址/usr/bin/git,maven地址
12.生成ssh秘钥:#ssh-****** -t rsa
13.将公钥给gitlab,设置Jenkins凭据,用户密码为gitlab用户和密码
14.系统配置———>Publish over SSH——>复制私钥的路径和key——>新增ssh server ————>远程服务器,目录为Tomcat war包目录/usr/local/tomcat2/webapps/————>测试连接
14.添加gitlab地址与主机名到/etc/hosts
ip gitlab.test.com
15.上传测试git代码:git clone [email protected]:Jay-Fred/one.git
cd one/
echo "test" >> test.txt
git config --global user.email "[email protected]"
git config --global user.name "jay-fred"
git add *
git commit -m "add test.txt"
git push
删除代码:git clone [email protected]:Jay-Fred/one.git
cd one/
rm -rf */dir/file
git add --all
git commit -m "delete dir"
git push
16.创建*工程
构建:调用顶层maven目标:maven——clean package
构建后操作:send build artifacts over ssh ——source file:Jenkins工作目录下的项目目录(/root/.jenkins/workspace/项目名),可写为:**/*.war,缺省目录为target(自动创建)
确定构建
推荐阅读