我设法编写了一个脚本,它通过minicom发送一些命令,并将它们存储在output.txt上。调用minicom的脚本称为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命令中,我给出了另一个名为serial的文件,其中包含一些runscript代码。
# 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根据其manual终止minicom终端。正如我前面提到的,当我在本地运行这个脚本时,或者当我通过ssh从我的本地机器调用脚本时,它可以正常运行。当我从jenkins运行这个命令时,问题就出现了。
output.txt文件被创建,但在Jenkins上仍然是空的,我收到了一条minicom消息,如下所示:
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之后,我希望它登录到主板(没有密码,只有超级用户)并运行systemctl is-system-running --wait。所有输出必须在output.txt上
同样,当手动运行或通过SSH从我的机器触发时,这就像预期的那样工作,但当从Jenkins触发时(添加了一个构建步骤execute shell,尝试使用SSH并启动脚本),它就不能工作。
在这一点上,我觉得这只是一个小问题,在这种情况下,我欢迎任何使用screen的解决方案
发布于 2020-10-05 18:33:59
我相信这是因为killall导致minicom向操作系统返回错误代码,Jenkins对此进行评估,因此认为它是失败的。如果这是原因,您可以添加try/catch块来标记构建不稳定或成功。
https://stackoverflow.com/questions/55028380
复制相似问题