赞
踩
序号 | 系统 | 内存 | CPU | IP地址 | 备注 |
---|---|---|---|---|---|
1 | CentOS | 4G | 4 | 192.168.61.68 | 项目部署 |
2 | CentOS | 4G | 4 | 192.168.61.69 | Jenkins安装 |
3 | CentOS | 4G | 4 | 192.168.61.69 | Ngrok安装 |
参考链接:https://blog.csdn.net/weixin_41668084/article/details/113517910
参考链接:https://blog.csdn.net/weixin_41668084/article/details/113730829
①**Maven Integration:新建job时有maven项目可以选择;
②Deploy to container:将war包部署到tomcat所在的服务器上;
③Publish Over SSH:**通过ssh推送文件,并可以执行shell命令;
点击:“系统管理”------>“全局工具配置”
配置Maven,Git,JDK
点击“系统管理”---->“系统设置”,进行ssh配置
[root@localhost bin]# ./sunny clientid 申请的服务id
添加GitHub地址
添加钩子
#!/bin/bash source /etc/profile chmod 755 /app/jenkins-test.jar count=`ps -ef|grep java|grep jenkins-test.jar |awk '{print $2}'` if [ $count -gt 0 ]; then echo '原进程:'$count echo '重新启动中...' kill -9 $count sleep 1 export BUILD_ID=dontKillMe (java -jar /app/jenkins-test.jar > /app/log/log.log 2>&1 &) else echo '启动中...' sleep 1 export BUILD_ID=dontKillMe (java -jar /app/jenkins-test.jar > /app/log/log.log 2>&1 &) fi echo '现进程:' `ps -ef|grep java|grep jenkins-test.jar |awk '{print $2}'`
发布日志
Started by user root Running as SYSTEM Building in workspace /var/lib/jenkins/workspace/test The recommended git tool is: NONE using credential 9bb2fab5-c4f1-4952-a1b1-1a5604d5d666 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > /usr/bin/git config remote.origin.url https://github.com/shuangxinyuan/jenkins.git # timeout=10 Fetching upstream changes from https://github.com/shuangxinyuan/jenkins.git > /usr/bin/git --version # timeout=10 > git --version # 'git version 1.8.3.1' using GIT_ASKPASS to set credentials > /usr/bin/git fetch --tags --progress https://github.com/shuangxinyuan/jenkins.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10 Checking out Revision ce2b7c87e27b3430a91ccc13462439d565d61fb3 (refs/remotes/origin/master) > /usr/bin/git config core.sparsecheckout # timeout=10 > /usr/bin/git checkout -f ce2b7c87e27b3430a91ccc13462439d565d61fb3 # timeout=10 Commit message: "Jenkins 测试-Ngrok-4" > /usr/bin/git rev-list --no-walk ce2b7c87e27b3430a91ccc13462439d565d61fb3 # timeout=10 [test] $ /usr/local/maven/bin/mvn -s /usr/local/maven/conf/settings.xml -gs /usr/local/maven/conf/settings.xml -DskipTests=true clean compile package [INFO] Scanning for projects... [INFO] [INFO] --------------------------< com.test:jenkins >-------------------------- [INFO] Building jenkins 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ jenkins --- [INFO] Deleting /var/lib/jenkins/workspace/test/target [INFO] [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ jenkins --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ jenkins --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /var/lib/jenkins/workspace/test/target/classes [INFO] [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ jenkins --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ jenkins --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /var/lib/jenkins/workspace/test/target/classes [INFO] [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ jenkins --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/test/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ jenkins --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /var/lib/jenkins/workspace/test/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ jenkins --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ jenkins --- [INFO] Building jar: /var/lib/jenkins/workspace/test/target/jenkins-test.jar [INFO] [INFO] --- spring-boot-maven-plugin:2.3.5.RELEASE:repackage (repackage) @ jenkins --- [INFO] Replacing main artifact with repackaged archive [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 7.523 s [INFO] Finished at: 2021-02-08T23:49:39+08:00 [INFO] ------------------------------------------------------------------------ SSH: Connecting from host [localhost.localdomain] SSH: Connecting with configuration [idea-maven-test] ... SSH: EXEC: completed after 1,206 ms SSH: Disconnecting configuration [idea-maven-test] ... SSH: Transferred 1 file(s) Finished: SUCCESS
项目进程查看
页面校验
代码修改
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--<h1>Welcome to Jenkins-Ngrok </h1>-->
<h1>Welcome To Jenkins-Ngrok </h1>
</body>
</html>
代码提交
Jenkins自动发布
#!/bin/bash source /etc/profile chmod 755 /app/jenkins/Jenkins-GitHub-Ngrok.jar count=`ps -ef|grep java|grep Jenkins-GitHub-Ngrok.jar |awk '{print $2}'` if [ $count -gt 0 ]; then echo '原进程:'$count echo '重新启动中...' kill -9 $count sleep 1 export BUILD_ID=dontKillMe (java -jar /app/jenkins/Jenkins-GitHub-Ngrok.jar > /app/jenkins/log/log.log 2>&1 &) else echo '启动中...' sleep 1 export BUILD_ID=dontKillMe (java -jar /app/jenkins/Jenkins-GitHub-Ngrok.jar > /app/jenkins/log/log.log 2>&1 &) fi echo '现进程:' `ps -ef|grep java|grep Jenkins-GitHub-Ngrok.jar |awk '{print $2}'`
yum安装的Jenkins 配置文件默认位置/etc/sysconfig/jenkins
默认jenkins服务以jenkins用户运行,这时在jenkins执行maven脚本时可能会发生没有权限操作某个目录下的文件,覆盖文件等情况。例如可能会报下面的错误。
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.5.2:install (default-install) on project icps-parent: Failed to install artifact io.binghe:binghe-parent:pom:1.0.0-SNAPSHOT: /home/repository/io/binghe/binghe-parent/1.0.0-SNAPSHOT/binghe-parent-1.0.0-SNAPSHOT.pom (权限不够) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
可以让jenkins以root用户运行来解决这个问题
gpasswd -a jenkins root
#user id to be invoked as (otherwise will run as root; not wise!)
JENKINS_USER=root
JENKINS_GROUP=root
可以修改为root权限运行
重启服务,搞定。
[ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-readable POM /var/lib/jenkins/workspace/zblog\code\pom.xml: /var/lib/jenkins/workspace/zblog\code\pom.xml (No such file or directory) @ @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project (/var/lib/jenkins/workspace/zblog\code\pom.xml) has 1 error [ERROR] Non-readable POM /var/lib/jenkins/workspace/zblog\code\pom.xml: /var/lib/jenkins/workspace/zblog\code\pom.xml (No such file or directory) [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException Build step 'Invoke top-level Maven targets' marked build as failure [DeployPublisher][INFO] Build failed, project not deployed Finished: FAILURE
报错的大致意思是:
不能从配置的Git仓库中找到pom.xml文件。
查看Jenkins工作空间下是否有pom.xml文件。
发现我的工作空间下没有pom.xml文件,我的pom.xml文件在code目录下。但是Jenkins配置时候默认是找工作空间下的pom.xml。
解决方案:修改Jenkins查找pom.xml文件的路径。
重新构建即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。