如何在文件系统上定位共享库?

时间:2021-07-21 08:06:10

标签: jenkins

我需要访问共享库(不是 resources/)的文件才能将其中的脚本上传到远程主机。为此,我需要在文件系统上找到共享库的克隆。

我已经构建了一个帮助程序来执行此操作,但是这种方法存在缺陷。当作业正确关闭(即不使用 /kill 端点)和(我假设)没有并发作业时,它运行良好。否则 Jenkins 会在工作区中创建带有后缀的唯一路径,而这种天真的方法会失败。

String locatePathToSharedLib(String nameOfSharedLib) {
    String expectedPath = env.WORKSPACE + "@libs/" + nameOfSharedLib
    if (!new File(expectedPath).isDirectory()) {
        exitWithError("Failed to find shared library at expected path: " + expectedPath)
    }
    return expectedPath
}

我的印象是使用像下面这样的简单助手应该可以实现,但这完全失败了。在 Java 中,这会返回项目的根路径,但在 Jenkins 的管道脚本中运行时,它会返回 Jenkins 主文件夹位置。

static String getPathToSharedLibrary() {
    return new File("").getAbsolutePath()
}

共享库的位置似乎也不存在于 Jenkins 环境变量中。

感谢您的任何建议!

0 个答案:

没有答案
相关问题