jenkins部署


Jenkins 插件安装加速

cd /opt/jenkins_home/updates

sed -i 's/https:\/\/updates.jenkins.io\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && \
sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json

http://www.bubuko.com/infodetail-3175110.html
https://www.cnblogs.com/hellxz/p/jenkins_install_plugins_faster.html

插件镜像 https://wiki.jenkins-ci.org/display/JENKINS/Multiple+SCMs+Plugin
https://www.cnblogs.com/cfsxgogogo/p/12613211.html https://lework.github.io/2020/03/05/jenkins-update-center/
1.测试镜像CDN速度
curl -sSL https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/speed-test.sh | bash
2.下载证书 
[ ! -d /var/lib/jenkins/update-center-rootCAs ] && mkdir /opt/jenkins/update-center-rootCAs
wget https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/rootCA/update-center.crt -O /opt/jenkins/update-center-rootCAs/update-center.crt
wget https://cdn.jsdelivr.net/gh/lework/jenkins-update-center@master/rootCA/update-center.crt -O update-center-rootCAs/update-center.crt

chown jenkins.jenkins -R /var/lib/jenkins/update-center-rootCAs
3.修改使用源
sed -i 's#https://updates.jenkins.io/update-center.json#https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json#' /opt/jenkins/hudson.model.UpdateCenter.xml

jenkins持续集成 概念

  1. 持续集成(Continuous integration)是一种软件开发实践
  2. 团队开发成员经常集成他们的工作,通常每个成员每天至少集成一次
  3. 每天可能会发生多次集成
  4. 每次集成都通过自动化的构建(包括编译、发布、自动化测试)来验证
  5. 结果就是能够尽早地发现集成错误

安装

1 war包启动

dnf install java-1.8.0-openjdk
java -jar jenkins.war --httpPort=8080

2 rpm包安装

  sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
  sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

wget https://pkg.jenkins.io/redhat-stable/jenkins-2.222.3-1.1.noarch.rpm   jenkins官网
yum -y install jenkins-2.164.2-1.1.noarch.rpm
vim /etc/sysconfig/jenkins    //自定义端口,修改下面参数项
service jenkins start

/var/lib/jenkins/hudson.model.UpdateCenter.xml
    <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>


rpm -ivh jenkins.noarch.rpm
yum -y localinstall *

/usr/lib/jenkins/jenkins.war    WAR包
/etc/sysconfig/jenkins       配置文件
/var/lib/jenkins/        默认的JENKINS_HOME目录
/var/log/jenkins/jenkins.log    Jenkins日志文件

# Firewalld
# /etc/sysconfig/iptables 文件中添加以下配置 以开放jenkins服务
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 8080 -j ACCEPT
-A OUTPUT -p tcp -m state --state ESTABLISHED -m tcp --sport 8080 -j ACCEPT
#注:如果jenkins有从节点,请开放到从节点的端口通常最方便的做法是开放ip或段的白名单
-A INPUT -s 10.8.0.0/16 -m state --state NEW,ESTABLISHED -m comment --comment "Allow 10.8.0.0/16 IN" -j ACCEPT
-A OUTPUT -d 10.8.0.0/16 -m state --state NEW,ESTABLISHED -m comment --comment "Allow 10.8.0.0/16 OUT" -j ACCEPT

3 docker安装

# https://github.com/jenkinsci/docker/blob/master/README.md
#docker pull jenkins/jenkins:2.289.1-lts-centos7
docker run -u root -d --restart=always --name=jenkins 
  -p 8088:8080 \
  -v /opt/jenkins:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkins/jenkins:2.289.1-lts-centos7
# -p 50000:50000 \

构建完成邮件通知

配置项目构建完成后邮件通知
https://www.cnblogs.com/imyalost/p/8781759.html
guanfei@merkletrees.cn    19781-merkletrees
cms@merkletrees.cn
smtp.qiye.aliyun.com  25

jenkins.noarch   2.222.3-1.1
1.jenkins安装邮箱插件  系统管理 -- 管理插件 -- 搜索插件并安装重启 Email Extension Plugin
2.配置系统邮箱   系统管理 -- 系统设置 -- jenkins Location  // Extended E-mail Notification  //  邮件通知 SMTP
3.job任务添加构建后操作发送邮件,填写接受人

填写上了默认发件人,那么默认发件人会收到所有的构建邮件

jenkins webhooks触发 jenkins.docs

Gitlab+Jenkins自动触发构建和发布
Gitlab+Jenkins 自动构建
[后端]gitlab之webhook自动部署

jenkins直推jvm包

Jenkins设置自动打包部署测试发布项目 maven项目
git repo 分支和账号
mvn339
package -Dmaven.test.skip=true -Pgray
clean package -Dmaven.test.skip=true -Ponline    
mvn clean install -Dmaven.test.skil=true        #clean 清除之前的jar包 install打包到本地,跳过测试代码

#!/bin/sh
#scp -r /var/lib/jenkins/workspace/test_male_chain/member/target/wallet_test.jar 47.52.102.159:/home/wallet_test.jar

#到目标服务器47.52.102.159发布jar服务(执行下面脚本即可)
ssh root@47.52.102.159  /home/wallet.sh

#publish.sh
#备份原有war包,停止服务进程,删除现有包,移动新包,启动包
#!/bin/bash
#用于执行jenkins包的脚本
#cd /home
#nohup java -Xms1024m -Xmx2048m -XX:+PrintGCDetails -jar member-1.0-SNAPSHOT.jar --server.port=8090 > bipay-core.log 2>&1 &

#!/bin/bash
#DATE=`date +%F-%H-%M`
#PROJECT_TARGET='wallet_admin_test'
#BACKUP_DIR='/backup'
#TOMCAT_HOME='/home/cat_admin'
#source /etc/profile
#停止tomcat服务
#echo '开始更新服务'
#echo '停止$PROJECT_TARGET测试项目'
#sh ${TOMCAT_HOME}/bin/shutdown.sh
#ps -ef | grep ${TOMCAT_HOME}/ | grep -v grep| awk '{print $2}' | xargs kill -9

#echo  '正在备份war包'
#cp ${TOMCAT_HOME}/webapps/${PROJECT_TARGET}.war ${BACKUP_DIR}/cat${PROJECT}-${DATE}.war

#echo  '正在删除原始war包信息'
#rm -rf ${TOMCAT_HOME}/webapps/${PROJECT_TARGET}.war
#rm -rf ${TOMCAT_HOME}/webapps/${PROJECT_TARGET}


#echo '将war包移动到项目目录'
#mv /home/${PROJECT_TARGET}.war  ${TOMCAT_HOME}/webapps/${PROJECT_TARGET}.war
#
##启动tomcat服务
#echo '启动wallet项目'
#sh ${TOMCAT_HOME}/bin/startup.sh

安装maven

#[maven官网地址 ](http://maven.apache.org/download.cgi "maven官网地址 ")
cd /opt && \
wget https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

cat  >> /etc/profile << eof
export MAVEN_HOME=/opt/maven363
export PATH=$PATH:$MMAVEN_HOME/bin
eof

. /etc/profile
mvn -version

阿里镜像源
vim ..maven363/conf/settings.xml
  <mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

本地仓库位置
<localRepository>/opt/maven363/repo</localRepository>

PS

BUILD_ID=DONTKILLME    #jenkin构建完成会在自动关闭进程及其子进程时,添加了这个就是不要杀死server进程
. /etc/profile
#配置运行参数
export PROJ_PATH=`pwd`

sh $PROJ_PATH/order/deploy.sh

cp /var/lib/jenkins/workspace/root_spring_demo/target/demo-0.0.1-SNAPSHOT.jar /usr/local/java/project/demo.jar
cd /usr/local/java/project/
nohup java -jar demo.jar --server.port=9000 > log.file 2>&1 &

Jenkins下载多git代码插件 
Multiple SCMs plugin

中文插件  Localization: Chinese (Simplified)     locale

https://www.jianshu.com/p/733cfa75ff8b Android打包
https://www.jianshu.com/p/4057f6d89584 IOS打包

https://ci.jenkins.io/

image

posted @ 2021-10-02 19:29  AlexG  阅读(105)  评论(0编辑  收藏  举报