Input Jenkins-如何在运行时与脚本输入交互

Input Jenkins-如何在运行时与脚本输入交互,input,jenkins,runtime,interactive,Input,Jenkins,Runtime,Interactive,我有一个小脚本,它生成两个随机数,将它们相加,并提示用户(如果总和>或

我有一个小脚本,它生成两个随机数,将它们相加,并提示用户(如果总和>或<特定值)--是否继续

因此,脚本是:

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$

脚本的run std.output很少是:

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$ ./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$
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$ ./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次时,它给出的和值小于3500,因此我按下“n”(这是我的自动化需要的一个必须的用户提示/输入,在这里,我举了这个和示例并进行了提示,只是为了说明我的情况),当它小于3500时,我按下“y”,N总值小于3500之前的次数

现在,詹金斯怎么能做到这一点

我不能使用参数化构建插件,因为(A和B变量是随机生成的,所以我不希望用户传递它),即调用脚本时不需要以下技巧:

回显“输入”|脚本或命令

脚本\u或\u命令

其次,用户要继续的输入(按y或n)取决于这两个随机变量值的总和。用户不知道在最后按“n”进入/退出脚本之前,他必须按“y”多少次。换句话说,用户可以提前硬编码输入(因为他的输入取决于运行时)。注意:我不想让人工智能足以用求和值作为用户输入来做决定,继续下去是我在Jenkins的要求

如果我在Jenkins中将我的脚本称为“use_random.sh”,你知道如何让它工作吗


Giga AKS

除非您使用某种“AI”,否则无法测试这是任何类型的连续测试系统。在您的例子中,这应该相对简单——您只需要编写第二个脚本来调用第一个脚本,提取SUM的值(例如使用grep),并生成相应的输入发送到第一个脚本。

事实上,如果这样的脚本很少,我会同意您的意见

但是,我有数百个这样的脚本,提示用户输入“基于运行时条件的”输入

例如:当用户说-每天以不同的顺序运行一些东西(5个文件/命令等),这些东西(文件/命令)本质上是随机的,因为/对于一个项目/应用程序。选择值继续/运行另一个脚本/ssh到1-N ssh服务器取决于这些因素。考虑这种情况:即,我得到shell选择“菜单”选项,其中文件/命令/应用程序可以在4或几天内,它可以在13或15。因此,取决于操作系统或应用程序的当前状态,我试图弄清楚的是,简言之:

我们可以使用Jenkins作业来实现这一点,而不是看有多少其他方法,有没有简单/清晰的方法来运行上面我想要的内容(例如,在控制台输出窗口中运行脚本时,Jenkins会提示“用户输入”…-非常像我们在Linux/Unix$prompt上运行脚本时所做的)
谢谢您的回复