jenkins的简介
Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件项目可以进行持续集成
Jenkins功能包括:
1、持续的软件版本发布/测试项目。
2、监控外部调用执行的工作。
更详细的Jenkins介绍请看此链接:
tomcat安装请看此链接tomcat-CSDN博客
jenkins安装
在jenkins官网上下载jenkins的war包
下载地址Jenkins download and deployment
[root@localhost ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.80.tar.gz index.jsp jenkins.war[root@localhost ~]# java -jar jenkins.war
[root@localhost ~]# cd /usr/local/tomcat/webapps/
[root@localhost webapps]# ls
docs examples host-manager manager ROOT test
[root@localhost webapps]# cp /root/jenkins.war /usr/local/tomcat/webapps/
[root@localhost webapps]# ls
docs examples host-manager jenkins.war manager ROOT test
[root@localhost ~]# alternatives --config java (选java17)
[root@localhost webapps]# /usr/local/tomcat/bin/catalina.sh stop
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost webapps]# /usr/local/tomcat/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.[root@localhost webapps]# ls
docs examples host-manager jenkins jenkins.war manager ROOT test
访问时在8080后面要加上jenkins
密码
[root@localhost webapps]# cat /root/.jenkins/secrets/initialAdminPassword
92dccb254b524e0da0d55161b671af3e
选择推荐安装
安装git命令
[root@localhost ~]# yum -y install git maven
然后选择高级项目选项,添加一个流水线脚本
然后保存
拉取项目
[root@localhost ~]# git clone https://gitee.com/forgotten/tomcat-java-demo.git
[root@localhost ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.80.tar.gz index.jsp jenkins.war tomcat-java-demo[root@localhost ~]#cd tomcat-java-demo
[root@localhost tomcat-java-demo]# mvn clean package
[root@localhost tomcat-java-demo]# cd target/
[root@localhost target]# ls
classes ly-simple-tomcat-0.0.1-SNAPSHOT maven-archiver
generated-sources ly-simple-tomcat-0.0.1-SNAPSHOT.war maven-status
流水线脚本
pipeline {
agent any
stages {
stage("pull code"){
steps {
git 'https://gitee.com/forgotten/tomcat-java-demo.git'
}
}
stage("make pkg"){
steps {
sh """
mvn clean package -Dmaven.test.skip=true
"""
}
}
stage("publish"){
steps {
sh """
cp /root/tomcat-java-demo/target/ly-simple-tomcat-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/
/usr/local/tomcat/bin/catalina.sh stop && /usr/local/tomcat/bin/catalina.sh start
"""
}
}
}
}