我有一个 Java 项目,正在通过 Windows 服务器上的 Jenkins 远程构建并运行一些 Cucumber 测试。测试完成运行后,我将创建一个进程来执行 Putty pscp 命令以将文件传输到 linux 服务器。当我在本地运行代码时,它运行良好。当我在 Jenkins 正在构建项目的远程 Windows 服务器上手动运行 pscp 传输命令时,它运行良好。但是无论出于何种原因,当通过 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);
}