gpt4 book ai didi

docker - 如何使后续的 check out scm阶段在Jenkins管道中使用本地 repo ?

转载 作者:行者123 更新时间:2023-12-02 21:14:53 25 4
gpt4 key购买 nike

我们使用Jenkins ECS插件为我们构建的“每个”作业生成Docker容器。所以我们的管道看起来像

node ('linux') {
stage('comp-0') {
checkout scm
}
parallel(
"comp-1": {
node('linux') {
checkout scm
...
}
}
"comp-2": {
node('linux') {
checkout scm
...
}
}
)
}

上面的管道将产生3个容器,每个节点('linux')调用一个。

我们在Jenkins配置页面中设置了一个'linux'节点,以告知Jenkins我们想要产生的Docker repo / image。它的设置具有“容器安装点”的概念,我认为是容器可以访问的主机上的安装。

因此,在上述管道中,我希望“第一个” checkout scm将我们的存储库克隆到由我们的容器安装的主机路径上,例如/ tmp / git。然后,我希望后续的“checkout scm”行将克隆的存储库复制到主机的/ tmp / git路径中。

我正在查看 How to mount Jenkins workspace in docker container using Jenkins pipeline以查看如何将本地路径安装到我的docker上

这可能吗?

最佳答案

您可以从checkout scm步骤中存储代码,然后在后续步骤中将其存储。这是Jenkins管道文档中的示例。

// First we'll generate a text file in a subdirectory on one node and stash it.
stage "first step on first node"

// Run on a node with the "first-node" label.
node('first-node') {
// Make the output directory.
sh "mkdir -p output"

// Write a text file there.
writeFile file: "output/somefile", text: "Hey look, some text."

// Stash that directory and file.
// Note that the includes could be "output/", "output/*" as below, or even
// "output/**/*" - it all works out basically the same.
stash name: "first-stash", includes: "output/*"
}

// Next, we'll make a new directory on a second node, and unstash the original
// into that new directory, rather than into the root of the build.
stage "second step on second node"

// Run on a node with the "second-node" label.
node('second-node') {
// Run the unstash from within that directory!
dir("first-stash") {
unstash "first-stash"
}

// Look, no output directory under the root!
// pwd() outputs the current directory Pipeline is running in.
sh "ls -la ${pwd()}"

// And look, output directory is there under first-stash!
sh "ls -la ${pwd()}/first-stash"
}

Jenkins Documentation on Stash/Unstash

关于docker - 如何使后续的 check out scm阶段在Jenkins管道中使用本地 repo ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51791709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com