带有 docker-workflow-plugin .inside 的 Jenkins 管道 DSL 不允许通过 withEnv 的 setting/modification PATH
Jenkins pipeline DSL with docker-workflow-plugin .inside doesn't allow setting/modification of PATH via withEnv
问题
我想修改 docker 容器中的路径来控制工具选择,而不需要修改现有的管道代码。我有一个共享库和客户端构建调用 runAnsible,然后通过 docker-workflow-plugin.
在 docker 容器中运行管道 DSL
但是,当我使用withEnv
docker.inside时,我无法修改路径
docker.inside() {
withEnv("PATH=${env.PATH}:/ansible2.10/bin") {
sh 'echo PATH=$PATH'
}
}
当结果为 PATH= 旧路径值且不包含我的修改时。根据 JENKINS-45916 这不是错误,而是它是如何工作的,我们都告诉过 - 不要那样做,使用不同的图像等
那么,除了制作一堆具有不同路径的非常相似的图像之外,我还有什么选择可以改变路径?
Docker 工作流插件允许将参数传递给创建容器的 docker 运行 命令。这些参数只是一个字符串,它的完整性似乎受到插件的尊重,而 withEnv
在这种情况下有某种过滤器。
因此,这可行,但它确实假设我知道或可以确定原始路径。我可以在不修改路径的情况下 运行 容器,并通过 docker.inside 使用 sh(script: 'echo $PATH', returnStdout: true).trim()
在前面的步骤中获取 knownOriginalPath 来支付下面的代码
// hardcoded because I own the image or have determined what the image's path normally is
def knownOriginalPath="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
// my change to the path - in this case, a custom tool location used because I don't want to have to modify a bunch of existing pipeline code.
def pathModification="/ansible2.10/bin"
def desiredPath="${pathModification}:${knownOriginalPath}"
docker.withRegistry(...) {
// for now, the plugin seems to respect the integrity of the inside option string.
docker.image(..)inside("-e PATH=${desiredPath}") {
sh 'echo PATH = $PATH'
}
}
问题
我想修改 docker 容器中的路径来控制工具选择,而不需要修改现有的管道代码。我有一个共享库和客户端构建调用 runAnsible,然后通过 docker-workflow-plugin.
在 docker 容器中运行管道 DSL但是,当我使用withEnv
docker.inside时,我无法修改路径
docker.inside() {
withEnv("PATH=${env.PATH}:/ansible2.10/bin") {
sh 'echo PATH=$PATH'
}
}
当结果为 PATH= 旧路径值且不包含我的修改时。根据 JENKINS-45916 这不是错误,而是它是如何工作的,我们都告诉过 - 不要那样做,使用不同的图像等
那么,除了制作一堆具有不同路径的非常相似的图像之外,我还有什么选择可以改变路径?
Docker 工作流插件允许将参数传递给创建容器的 docker 运行 命令。这些参数只是一个字符串,它的完整性似乎受到插件的尊重,而 withEnv
在这种情况下有某种过滤器。
因此,这可行,但它确实假设我知道或可以确定原始路径。我可以在不修改路径的情况下 运行 容器,并通过 docker.inside 使用 sh(script: 'echo $PATH', returnStdout: true).trim()
在前面的步骤中获取 knownOriginalPath 来支付下面的代码
// hardcoded because I own the image or have determined what the image's path normally is
def knownOriginalPath="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
// my change to the path - in this case, a custom tool location used because I don't want to have to modify a bunch of existing pipeline code.
def pathModification="/ansible2.10/bin"
def desiredPath="${pathModification}:${knownOriginalPath}"
docker.withRegistry(...) {
// for now, the plugin seems to respect the integrity of the inside option string.
docker.image(..)inside("-e PATH=${desiredPath}") {
sh 'echo PATH = $PATH'
}
}