我有一个小脚本,它生成两个随机数,将它们相加并提示用户(如果 SUM 是 > 或 < 特定值)——继续与否。
因此,脚本是:
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 否。直到 SUM 值小于 3500 的次数。
现在,詹金斯怎么能做到这一点???
我不能使用参数化构建插件(A 和 B 变量是随机生成的,所以我不希望用户传递它)即,调用脚本时不需要以下技巧:
回声“输入” | script_or_command
或
script_or_command < file_with_input
其次,用户的继续输入(按 y 或 n)取决于这 2 个随机变量值的总和。用户不知道在最终按“n”进入/退出脚本之前他必须按多少次“y”。换句话说,用户可以提前对输入进行硬编码(因为他的输入取决于运行时)。注意:我不想让 AI 足以使用 SUM 值作为用户输入来做出决策以继续是我想要在 Jenkins 中做的要求。
如果我在 Jenkins 中调用我的脚本“use_random.sh”,有什么想法可以让它工作吗?
千兆AKS