jenkins-learning

常规的打包方式:

提交代码
拉去代码并打包:war包和jar包
上传到服务器
关闭当前程序
启动新的jar包
查看新的jar包是否起作用

 

jenkins自动化流程:

 

CI(Continuous integration,中文意思是持续集成)是一种软件开发时间。持续集成强调开发人员提交了新代码之后,立刻进行构建、(单元)测试

 

 

CD(Continuous Delivery, 中文意思持续交付)是在持续集成的基础上,将集成后的代码部署到更贴近真实运行环境(类生产环境)中 

 

 

所以CD是在CI的基础上的操作,简单来讲就是持续部署, 

 

 jenkins需要的环境是jdk环境+git环境+maven环境去部署java程序:

 

mac使用brew安装完成之后:brew services start jenkins 启动:

 

先进行基本的配置先:

 

 

 

 

 

 配置

 

配置全局的环境:

 

 

maven:

 

 git

 

 

jdk:

 

安装插件

安装ssh插件:publish over ssh

安装maven项目插件:Maven Integration plugin

 

新建一个maven项目:

 

 

编写ssh server相关:

 

 

在全局配置里面配置需要登陆的服务器:

 

 

可以点击测试一下是否能够链接到服务器。

Remote Directory 上传到的服务器的那个目录下,非常重要,因为要进入到这个目录去执行jar包

 

 

执行的命令里面的脚本:

[root@better.qzqlsj.club jenkinsJar]$cat start.sh 
#/bin/bash
 /usr/bin/java -jar quan-0.0.1-SNAPSHOT.jar &
if [  $? -eq 0 ]
    then 
    echo "done"
else
    echo "back"
fi

 

[root@better.qzqlsj.club jenkinsJar]$cat stop.sh 
#!/bin/bash
echo "Stop Procedure : quan-0.0.1-SNAPSHOT.jar"
pid=`ps -ef |grep java|grep quan-0.0.1-SNAPSHOT.jar|awk '{print $2}'`
echo 'old Procedure pid:'$pid
if [ -n "$pid" ]
then
kill -9 $pid
fi

保存,点击构建即可:

Started by user huolala
Running as SYSTEM
Building in workspace /Users/quan/.jenkins/workspace/quan-login-test
using credential bcd9b4e9-9a63-49ad-a57c-485c07864954
 > /usr/local/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/local/bin/git config remote.origin.url https://gitlab.huolala.cn/group-arch/quan-monitor.git/ # timeout=10
Fetching upstream changes from https://gitlab.huolala.cn/group-arch/quan-monitor.git/
 > /usr/local/bin/git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > /usr/local/bin/git fetch --tags --progress -- https://gitlab.huolala.cn/group-arch/quan-monitor.git/ +refs/heads/*:refs/remotes/origin/* # timeout=10
 > /usr/local/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > /usr/local/bin/git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision e1f826aceabbd27307ecd4de965dc166574c03e2 (refs/remotes/origin/master)
 > /usr/local/bin/git config core.sparsecheckout # timeout=10
 > /usr/local/bin/git checkout -f e1f826aceabbd27307ecd4de965dc166574c03e2 # timeout=10
Commit message: "Update pom.xml"
 > /usr/local/bin/git rev-list --no-walk e1f826aceabbd27307ecd4de965dc166574c03e2 # timeout=10
Parsing POMs
Established TCP socket on 62030
[quan-login-test] $ /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/bin/java -cp /Users/quan/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.13.jar:/Users/quan/sotfware/apache-maven-3.6.3/boot/plexus-classworlds-2.6.0.jar:/Users/quan/sotfware/apache-maven-3.6.3/conf/logging jenkins.maven3.agent.Maven35Main /Users/quan/sotfware/apache-maven-3.6.3 /Users/quan/.jenkins/war/WEB-INF/lib/remoting-4.5.jar /Users/quan/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.13.jar /Users/quan/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 62030
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f /Users/quan/.jenkins/workspace/quan-login-test/pom.xml -s /Users/quan/sotfware/apache-maven-3.6.3/conf/settings.xml -gs /Users/quan/sotfware/apache-maven-3.6.3/conf/settings.xml install
2020-07-31 16:31:14.190 java[40895:478137] imkxpc_getApplicationProperty:reply: called with incorrect property value 4, bailing.
2020-07-31 16:31:14.190 java[40895:478137] Text input context does not respond to _valueForTIProperty:
2020-07-31 16:31:14.191 java[40895:478137] imkxpc_getApplicationProperty:reply: called with incorrect property value 4, bailing.
2020-07-31 16:31:14.191 java[40895:478137] Text input context does not respond to _valueForTIProperty:
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.quan.monitor:quan:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ line 59, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] -----------------------< com.quan.monitor:quan >------------------------
[INFO] Building quan 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
2020-07-31 16:31:15.704 java[40895:478137] imkxpc_getApplicationProperty:reply: called with incorrect property value 4, bailing.
2020-07-31 16:31:15.705 java[40895:478137] Text input context does not respond to _valueForTIProperty:
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ quan ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ quan ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /Users/quan/.jenkins/workspace/quan-login-test/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ quan ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/quan/.jenkins/workspace/quan-login-test/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ quan ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ quan ---
[INFO] Surefire report directory: /Users/quan/.jenkins/workspace/quan-login-test/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[JENKINS] Recording test results
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ quan ---
[INFO] Building jar: /Users/quan/.jenkins/workspace/quan-login-test/target/quan-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.3.2.RELEASE:repackage (default) @ quan ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-source-plugin:2.1.2:jar-no-fork (attach-sources) @ quan ---
[INFO] Building jar: /Users/quan/.jenkins/workspace/quan-login-test/target/quan-0.0.1-SNAPSHOT-sources.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ quan ---
[INFO] Installing /Users/quan/.jenkins/workspace/quan-login-test/target/quan-0.0.1-SNAPSHOT.jar to /Users/quan/.m2/repository/com/quan/monitor/quan/0.0.1-SNAPSHOT/quan-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/quan/.jenkins/workspace/quan-login-test/pom.xml to /Users/quan/.m2/repository/com/quan/monitor/quan/0.0.1-SNAPSHOT/quan-0.0.1-SNAPSHOT.pom
[INFO] Installing /Users/quan/.jenkins/workspace/quan-login-test/target/quan-0.0.1-SNAPSHOT-sources.jar to /Users/quan/.m2/repository/com/quan/monitor/quan/0.0.1-SNAPSHOT/quan-0.0.1-SNAPSHOT-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.416 s
[INFO] Finished at: 2020-07-31T16:31:20+08:00
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /Users/quan/.jenkins/workspace/quan-login-test/pom.xml to com.quan.monitor/quan/0.0.1-SNAPSHOT/quan-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /Users/quan/.jenkins/workspace/quan-login-test/target/quan-0.0.1-SNAPSHOT.jar to com.quan.monitor/quan/0.0.1-SNAPSHOT/quan-0.0.1-SNAPSHOT.jar
[JENKINS] Archiving /Users/quan/.jenkins/workspace/quan-login-test/target/quan-0.0.1-SNAPSHOT-sources.jar to com.quan.monitor/quan/0.0.1-SNAPSHOT/quan-0.0.1-SNAPSHOT-sources.jar
channel stopped
SSH: Connecting from host [quandeMacBook-Pro.local]
SSH: Connecting with configuration [txy-1] ...
SSH: EXEC: STDOUT/STDERR from command [cd /jenkinsJar
./stop.sh
nohup sh start.sh] ...
Stop Procedure : quan-0.0.1-SNAPSHOT.jar
old Procedure pid:22316
nohup: ignoring input and appending output to `nohup.out'
SSH: EXEC: completed after 275 ms
SSH: Disconnecting configuration [txy-1] ...
SSH: Transferred 1 file(s)
Finished: SUCCESS

 

posted @ 2020-08-03 08:10  小丑quan  阅读(560)  评论(0)    收藏  举报