Jenkins 报错记录

解析 POM 错误

maven 仓库 repository 文件夹,权限设置默认的 644,Jenkins 默认 用户是 jenkins,没有权限。改成了 777。

kill 权限错误

jenkins kill: (): Operation not permitted

解决办法是使用 sudo 命令

使用 sudo 命令错误

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper

Jenkins 运行 shell 的用户和组

User=jenkins
Group=jenkins

把用户 jenkins 添加到 sudo 组(似乎这一步不太需要)

usermod -aG sudo jenkins

重启 Jenkins

systemctl restart jenkins

修改 /etc/sudoers 文件,让 sudo 命令不需要密码

visudo -f /etc/sudoers

添加一句

# 设置jenkins组的用户,执行 sudo 不需要密码
%jenkins ALL=(ALL) NOPASSWD:ALL

私钥报错

Publish over SSH 时,添加 SSH Server 的密钥,测试报错

jenkins.plugins.publish_over.BapPublisherException: Failed to add SSH key. Message [invalid privatekey: [B@21fc615f]

密钥首行

-----BEGIN OPENSSH PRIVATE KEY-----

使用的 Jenkins 版本 2.361.2

说是 Jenkins 现在还不支持这个格式的密钥

支持的格式首行是

-----BEGIN RSA PRIVATE KEY-----

需要重新生成密钥对

ssh-keygen -m PEM -t rsa -b 4096

-m 参数指定密钥的格式

-b 指定密钥长度。对于RSA密钥,最小要求768位,默认是2048位。

Jenkins 运行 shell 命令超时

Jenkins 运行 shell 命令超时

ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 120,001 ms]
Build step 'Send build artifacts over SSH' changed build result to UNSTABLE
Finished: UNSTABLE

shell 命令

ps -ef | grep hello | grep -v grep | awk '{print $2}' | xargs kill -9
sleep 2
nohup java -jar /opt/hello/hello-0.0.1-SNAPSHOT.jar

在目标服务器查看进程,发现进程 ID已经更新过了,也就是 shell 命令已经执行过了,但是 Jenkins 运行完 shell 命令没有退出。

在 SSH 终端上直接运行 shell 命令,发现不会立刻退出,而是会卡住,需要 Ctrl + C 才能跳出。

root@dev-VM:/opt/hello# nohup java -jar /opt/hello/hello-0.0.1-SNAPSHOT.jar
nohup: ignoring input and appending output to 'nohup.out'

直接退出的方式是,把输出信息写入日志文件。

ps -ef | grep hello | grep -v grep | awk '{print $2}' | xargs kill -9
sleep 2
nohup java -jar /opt/hello/hello-0.0.1-SNAPSHOT.jar > out.log 2>&1 &

运行命令直接返回

root@dev-VM:/opt/hello# nohup java -jar /opt/hello/hello-0.0.1-SNAPSHOT.jar > out.log 2>&1 &
[1] 425843
root@dev-VM:/opt/hello#
posted @ 2023-03-04 20:57  ioufev  阅读(489)  评论(0)    收藏  举报