jenkins实现自动化部署

经过五天的折腾,也算是初步实现自动化部署

操作系统 windows10

启动方式 java -jar 

war包版本2.261

参考链接:

https://www.cnblogs.com/wfd360/p/11314697.html

这位老哥写的还是够详细的,有几个地方还是有点不同,找了半天原因

问题1:找不到pom.xml文件

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\14199\.jenkins\workspace\项目自动化部署test). Please verify you invoked Maven from the correct directory. -> [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.

由于我们公司的git地址中下下来的文件包含了前端文件和后端文件,所以下下来的文件多了一层文件夹,由于jenkins在构建中找不到对应的pom.xml文件就会报错,而我只需要打包后端的服务,所以就需要在jenkins中指定pom.xml的文件路径

 

问题2: 读取pom文件失败

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.htmap.hngt:api:1.0 (C:\Users\14199\.jenkins\workspace\项目自动化部署test\HunanPlanning-service\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.htmap.hngt:api:1.0: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.3.3.RELEASE from/to nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public class="hljs-tag">): Illegal character in path at index 51: http://maven.aliyun.com/nexus/content/groups/public class="hljs-tag">/org/springframework/boot/spring-boot-starter-parent/2.3.3.RELEASE/spring-boot-starter-parent-2.3.3.RELEASE.pom and 'parent.relativePath' points at no local POM @ line 5, column 13 ->

说是读取这个pom.xml文件发现错误了,但是我在idea中使用是没有问题的,也没出现红色提醒,找了好久才发现,maven-conf目录下我有多个settings文件,而idea中使用的是settings+后缀的文件,但在jenkins中使用的却是settings.xml文件,后面改成idea中使用的配置文件就没报此错了,可能是pom.xml中没配置好

 

问题3:系统找不到指定的文件

[项目自动化部署test] $ sh -xe C:\Users\14199\AppData\Local\Temp\jenkins1265951208300673725.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: CreateProcess error=2, 系统找不到指定的文件。

这个错误在网上找了下是说在构建中打开了一个windows终端命令窗口,可能在里面输入了空格或者没输入任何东西导致了这个问题,把这个窗口删掉即可

问题4:jar包上传服务器未成功

SSH: Disconnecting configuration [测试服务器] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [1]]

 到目前为止看到的错误,其实和jar包上传没有关系,但是是日志中唯一看到的error了

因为前面说过目录多了一层,所以在设置上传服务目录时也需要多加一层目录才能成功,虽然是相对路径,但是少加了一层就是没有上传文件,加上就可以上传成功,比较奇怪

问题5:启动脚本文件没有权限

bash: line 1: ./stop_1.sh: Permission denied
bash: line 2: ./start_1.sh: Permission denied

执行chmod 777 start_1.sh 即可

 

问题6:找不到对应的路径

bash: ./stop_1.sh: /bin/bash^M: bad interpreter: No such file or directory

这个一般是 start.sh脚本中的路径不对,修改为自己的正确路径即可

 

问题7:换行符问题

./start_1.sh: line 7: $'\r': command not found

因为start.sh等脚本都是在window上编辑好了才上传到linux服务器上,Windows和linux换行符不一样导致的

下载dos2unix插件,执行 dos2unix start.sh 即可

 

问题8:执行完shell后,进程退出问题

这个在网上找的答案说加上BUILD_ID=dontKillMe命令就可以了,试过没什么用,后面还是用的前文博主里面提供的命令没有做任何删才启动成功

 

#成功的shell(这个格式怎么弄不了,服了)

#!/bin/bash
export JAVA_HOME=/usr/java/jdk1.8.0_231
echo ${JAVA_HOME}
echo 'Start the program : api-1.0.jar'
chmod 777 /usr/jenkinsTest/api-1.0.jar
echo '-------Starting-------'
cd /usr/jenkinsTest/
nohup ${JAVA_HOME}/bin/java -jar api-1.0.jar &
echo 'start success'


# 失败的shell
# echo 'Start the program : api-1.0.jar'
# echo '-------Starting-------'
# BUILD_ID=dontKillMe nohup java -jar /usr/jenkinsTest/api-1.0.jar &
# echo 'start success'

 

启动成功的日志会有spring boot 启动成功的日志

 

还有些小的问题,如图标显示的是黄色圆图标,表示是不稳定版本,暂时不清楚原因,后面在找吧,但是服务是能成功启动了

访问swagger成功,自动化部署成功!

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值