【问题标题】:Linux Jenkins test if file exists in windows shareLinux Jenkins 测试文件是否存在于 Windows 共享中
【发布时间】:2018-08-08 13:55:56
【问题描述】:

我有一个主 Linux Jenkins 服务器。我需要使用管道测试远程 Windows 共享上是否存在文件。

有没有简单的方法来做到这一点?我了解到 'fileExists' 仅适用于本地工作区,所以这不好。

这可能吗?或者我需要使用 sh 命令来做一些魔术吗?

谢谢!

克雷格

【问题讨论】:

  • 使用 NFS 将远程 FS 连接为本地文件夹。检查这个文件夹。
  • 如果 ssh 服务器在你的 windows 机器上运行,只需交换密钥并通过 ssh 连接。

标签: linux jenkins groovy jenkins-pipeline


【解决方案1】:

如果您在 Jenkins 服务器上安装了 LFTP,您可以尝试以下操作

$ lftp -c "open sftp://hostname_remote_windows_system ; find file_to_be_found.txt"

【讨论】:

    【解决方案2】:

    请注意fileExists()需要在节点上执行。那么:让一个 windows 节点连接到你的 Linux 主节点,执行fileExists(),比如:

    def fileDoesExist
    node('windows') {
        fileDoesExist = fileExists(pathToFile)
    }
    

    请注意,访问 Windows 文件共享需要 net use 一次。因此,为了使其在您之前从未访问过共享的新机器上也能正常工作:

    def fileDoesExist
    node('windows') {
        bat 'net use \\\\share\\path\\to\\some\\directory'
        fileDoesExist = fileExists('//share/path/to/file')
    }
    
    if (fileDoesExist) {
        // do someting here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      相关资源
      最近更新 更多