从 Jenkins 调用的小通信脚本在退出"! 基拉尔-9小通"时失败



我设法制作了一个脚本,该脚本通过minicom发送一些命令并将它们存储在输出中.txt。调用小通的脚本称为dut.sh

#!/bin/bash
echo "Setting up DUT" 
stm_armv7 -print "DUT"
stm_armv7 -dut
echo "wait 30s"
sleep 30s
stty -F /dev/ttyACM0 115200 cs8 -cstopb -parenb
rm /home/fsnk/scripts/serial-com/output.txt
export TERM=linux-c-nc
minicom -b 115200 -D /dev/ttyACM0 -C /home/fsnk/scripts/serial-com/output.txt -S /home/fsnk/scripts/serial-com/serial -o 
echo "wait another 5s"
sleep 5s
stm_armv7 -ts 

所以在minicom命令中,我给出了另一个名为 justserial的文件,其中包含一些运行脚本代码。

# UNIX login script.
# Can be used to automatically login to almost every UNIX box.
#
# Some variables.
set a 0
set b a
print Trying to Login..
# Skip initial 'send ""', it seems to matter sometimes..
send ""
goto login
login:
if a > 3 goto failed1
expect {
"ogin:"       send "root"  
"assword:"    send ""
timeout 5    goto loop1

}
goto loop1
loop1:
send "systemctl is-system-running --wait"
sleep 3
# Send command not more than three times.
inc b
if b > 3 goto failed1
expect {
"nrunning"    goto success1
break
"degrading"  goto success2        
break
timeout 5    goto failed2

}
success1:    
print nSuccessfully received running!
! killall -9 minicom
exit
success2:
print nSuccessfully received degrading!
! killall -9 minicom
exit
failed1:
print nConnection Failed (wrong password?)
! killall -9 minicom
exit
failed2: 
print nMessage sending failed. Didn't receive anything!
! killall -9 minicom
exit

该命令! killall -9 minicom根据其手册杀死迷你通信终端。正如我之前提到的,当我在本地运行它时,或者当我从本地机器通过 ssh 调用脚本时,它运行正常。当我从 jenkins 运行它时出现问题。

输出.txt文件被创建,但在 Jenkins 上保持为空,我收到如下小通信消息:

Setting up DUT
wait 30s
Welcome to minicom 2.7
OPTIONS: I18n 
Compiled on Apr 22 2017, 09:14:19.
Port /dev/ttyACM0, 16:30:57
Press CTRL-A Z for help on special keys
/home/fsnk/scripts/serial-com/dut.sh: line 12:  5639 Killed                  minicom -b 115200 -D /dev/ttyACM0 -C /home/fsnk/scripts/serial-com/output.txt -S /home/fsnk/scripts/serial-com/serial -o
wait another 5s
Finished: SUCCESS

在消息Press CTRL-A Z for help on special keys之后,我希望它登录到董事会(没有密码,只有root用户)并运行systemctl is-system-running --wait。所有输出都必须在输出上.txt

同样,当手动运行或通过 SSH 从我的机器进行尝试时,这就像预期的那样工作,但是当从 Jenkins 尝试(添加了一个尝试 SSH 和启动脚本的构建步骤execute shell)时,它不起作用。

在这一点上,我觉得这是一个迷你公司的问题,在这种情况下,我欢迎任何解决方案screen

我相信这是因为 killall 导致 minicom 向操作系统返回错误代码,Jenkins 对其进行了评估,因此认为这是失败的。如果这是原因,您可以添加 try/catch 块来标记构建不稳定或成功。

最新更新