且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不要接受价值观

更新时间:2023-02-27 09:24:31


can you give a basic idea how I can achieve it in Jenkins.

所以


  • 如果你的jar接受通过参数化构建在jenkins工作中传递它们的参数

  • 如果没有,而是提示你,你是在问题:你需要一种自动化控制台的方法。

这个工作的X平台工具是期望。关于它的坏处是它在Windows上需要大量的代码(如果你在Linux上运行它可能已经存在)。作为替代方案,您可以使用Autohotkey,但它无法轻松检测控制台文本(与预期读取控制台缓冲区不同)。但是,如果提示以确定的方式出现(即刚刚开始),您可以执行以下操作:

X-platform tool for the job is Expect. Bad thing about it is that it requires a lot of deps on Windows (if you are running this on Linux expect is probably already there). As alternative you could use Autohotkey altho it can't detect easily console text (unlike expect which reads console buffer). However if prompt appears in deterministic manner (i.e. just after start) you could do something like:

java -jar myfile.jar
sleep 5
autohotkey.exe SendKeys.ahk

SendKeys.ahk将是简单如下:

SendKeys.ahk would be as simple as:

 WinActivate <pid / window name ...>
 Send answer1<ENTER>answer2<ENTER> ....

但它可以更加强大,以便密钥发送不依赖于控制台窗口状态。

but it could be made more robust so that key sending will not depend on console window state.

在cmd中,您可以使用 title 命令设置一些特定的窗口名称,然后您可以使用AHK激活该标题。

In cmd you can set some specific window name with title command then you can activate that title with AHK.