运行Jenkins

时间:2016-03-21 15:59:31

标签: java selenium jenkins ftp ftp-client

我正在尝试从我的测试中下载FTP文件。 当我从我的本地PC或BrowserStack运行它时,它可以很好地工作,但是当我将它上传到jenkins时,它就会陷入困境。 我无法理解为什么它不能在Jenkins上运行? 我设法创建了与FTP的连接。下面显示的代码是下载文件的方法。

  

boolean success = ftpClient.retrieveFile(remoteFile,outputStream);

    public static File downloadFileFromFtp(String fileName, String ftpFilePath, String downloadDirectory, String fileExtension, ExtentTest test) throws Exception {
    FTPClient ftpClient = new FTPClient();
    ftpClient.connect(AutomationPropeties.ftpHost, Integer.valueOf(AutomationPropeties.ftpPort));
    ftpClient.login(AutomationPropeties.ftpUsername, AutomationPropeties.ftpPassword);
    ftpClient.enterLocalPassiveMode();
    System.out.println("loged in ftp");
    if (ftpClient.isConnected()) {
        test.log(LogStatus.INFO, "Connected Succesfuly to ftp server.");
        System.out.println("loged in ftp");
    } else {
        test.log(LogStatus.INFO, "Failed connecting to ftp.");
        System.out.println("not loged in ftp");
    }
    String remoteFile = ftpFilePath + fileName + ".xlsx";
    System.out.println(remoteFile);
    // File downloadFile = new File(downloadDirectory+fileName+".xlsx");

    File downloadFile = File.createTempFile(fileName, ".xlsx");
    System.out.println("reached the try");
    try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadFile))) {
        System.out.println("finished with the output");
        boolean success = ftpClient.retrieveFile(remoteFile, outputStream);
        System.out.println("retrive the file & conection closed");
        if (success) {
            test.log(LogStatus.PASS, "File was downloaded succesfuly");
        } else {
            test.log(LogStatus.FAIL, "Failed to download file");
        }
    } finally {
        ftpClient.logout();
        ftpClient.disconnect();
    }
    return downloadFile;
}

2 个答案:

答案 0 :(得分:0)

也许詹金斯FTP plugin就是你所需要的。詹金斯可以用工蜂定义(比奴隶好得多,你不觉得吗?)服务器,所以你的工作可能在不同的物理服务器上运行。

如果您查看插件,请报告是否有帮助。

<强>更新

使用:

curl -O ftp://server/path/to/file

答案 1 :(得分:0)

这是来自BrowserStack的Mukul。我们最近发布了一个可能会帮助您的Jenkins plugin