我设法制作了一个脚本,该脚本通过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
的文件,其中包含一些运行脚本代码。
# 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调用脚本时,它运行正常。当我从詹金斯运行此问题时,会发生问题。
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
之后,我希望它登录到开发板(无密码,只有root用户)并运行systemctl is-system-running --wait
。所有输出必须在output.txt上
同样,当手动运行或通过SSH从我的计算机触发时,此功能按预期运行,但从Jenkins触发(添加了尝试进行SSH并启动脚本的构建步骤execute shell
)时,此操作无效。
在这一点上,我觉得这是一个小型通信问题,在这种情况下,我欢迎使用screen
答案 0 :(得分:0)
我相信这是因为killall导致minicom向操作系统返回错误代码,詹金斯评估该错误代码,因此认为它是失败的。如果是原因,则可以添加一个try / catch块来标记构建不稳定或成功。