我有一个Java项目,该项目通过Windows服务器上的Jenkins远程构建并运行一些Cucumber测试。一旦测试完成运行,我将创建一个执行Putty pscp命令的过程,以将文件传输到Linux服务器。当我在本地运行代码时,该代码运行良好。当我在Jenkins构建项目的远程Windows服务器上手动运行pscp transfer命令时,该代码运行良好。但是无论出于什么原因,当通过Jenkins构建项目时……都不会发出命令。有任何想法吗? try Catch打印出它已成功发出命令,但是传输的文件未在linux服务器上显示为正在更新...所以我没有任何故障消息可帮助我在输出日志中对此进行调试
一些我已经证实的假设:
我要用于要传输的文件的路径正确。
文件未传输。
一些代码:
String updateJiraLocalPath = System.getProperty("user.dir")+"\\src\\test\\resources\\scripts\\updatejira.sh"; //Eclipse Project path
ProcessBuilder process= new ProcessBuilder("C:\\Putty\\0.6.3\\PSCP.EXE", "-r", "-l", "username@servername", "-pw", "serverPassword", updateJiraLocalPath, "username@servername:/tmp/username/dirToTransferFile");
p = process.start();
try {
final int exitValue = p.waitFor();
if (exitValue == 0){
String line;
System.out.println("Successfully executed the command);
BufferedReader br = new BufferedReader (new InputStreamReader(p.getInputStream()));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
input.close();
}
else {
System.out.println("Failed to execute the command: due to the following error(s):");
try (final BufferedReader b = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
String line;
if ((line = b.readLine()) != null)
System.out.println(line);
} catch (final IOException e) {
e.printStackTrace();
System.out.println(e);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println(e);
}