我有一個小腳本,它會生成兩個RANDOM數字,並添加它們並提示用戶(如果SUM>或<一個特定值) - 繼續或不。Jenkins - 如何與腳本輸入交互 - 運行期間
因此,腳本是:
bash-3.00$ cat use_random.sh
#!/bin/bash
func()
{
a=$RANDOM
b=$RANDOM
sum=`expr $a + $b`
echo A = $a
echo B = $b
echo
echo Sum of A + B is : $sum
}
choice=y;
until [ "$choice" == "n" ];
do
# call func
echo ---------------------------------------------; echo;
func;
echo Sleeping for 3 seconds...
sleep 3;
echo -
echo "IF SUM value is greater than 3500, then press 'n' otherwise, press 'y'"; echo;
echo -n "Do you want to continue (y/n)? : "; read choice;
echo ---------------------------------------------; echo;
done
bash-3.00$
和
幾個腳本的運行std.output是:
bash-3.00$ ./use_random.sh
---------------------------------------------
A = 20359
B = 15866
Sum of A + B is : 36225
Sleeping for 3 seconds...
-
IF SUM value is greater than 3500, then press 'n' otherwise, press 'y'
Do you want to continue (y/n)? : n
---------------------------------------------
bash-3.00$
的bash-3.00 $
bash-3.00$ ./use_random.sh
---------------------------------------------
A = 18058
B = 20395
Sum of A + B is : 38453
Sleeping for 3 seconds...
-
IF SUM value is greater than 3500, then press 'n' otherwise, press 'y'
Do you want to continue (y/n)? : n
---------------------------------------------
bash-3.00$
的bash-3.00 $ 的bash-3.00 $
bash-3.00$ ./use_random.sh
---------------------------------------------
A = 6016
B = 13489
Sum of A + B is : 19505
Sleeping for 3 seconds...
-
IF SUM value is greater than 3500, then press 'n' otherwise, press 'y'
Do you want to continue (y/n)? : y
---------------------------------------------
---------------------------------------------
A = 25837
B = 3852
Sum of A + B is : 29689
Sleeping for 3 seconds...
-
IF SUM value is greater than 3500, then press 'n' otherwise, press 'y'
Do you want to continue (y/n)? : y
---------------------------------------------
---------------------------------------------
A = 7565
B = 3220
Sum of A + B is : 10785
Sleeping for 3 seconds...
-
IF SUM value is greater than 3500, then press 'n' otherwise, press 'y'
Do you want to continue (y/n)? : y
---------------------------------------------
---------------------------------------------
A = 32092
B = 22688
Sum of A + B is : 54780
Sleeping for 3 seconds...
-
IF SUM value is greater than 3500, then press 'n' otherwise, press 'y'
Do you want to continue (y/n)? : n
---------------------------------------------
bash-3.00$
正如你看到的上面,當我跑第2次,這給了SUM值小於3500的劇本,所以我按下 「N」(這是一個必須的用戶提示/輸入爲我的自動化需要,在這裏我拿這個SUM例子,並提示只是爲了把我的情況),當它低於3500,然後我按「Y」,N號。的時間,直到總和值低於3500.
現在,怎麼能在Jenkins做到這一點?
我不能使用的參數生成插件(A和B變量是隨機生成的,所以我不希望用戶通過它),即同時調用腳本下面的技巧不要求:
回聲「輸入「| script_or_command
或
script_or_command < file_with_input
其次,用戶的輸入以繼續(按壓Y或N)取決於這些2隨機變量的值的總和。用戶不知道在最後按下「n」出現/退出劇本之前,他有多少次按「y」。換句話說,用戶可以預先硬輸入輸入(因爲他的輸入取決於運行時)。注意:我不想讓AI足以使用SUM值作爲用戶輸入繼續進行決策,這是我想要在Jenkins中完成的要求。
任何想法,我可以得到這個工作,以防萬一我在詹金斯稱我的腳本「use_random.sh」?
千兆AKS