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

标签 docker jenkins jenkins-pipeline

我们使用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/

相关文章:

jenkins - 如何使用 Pipeline Utility Steps 插件更新现有 yaml 文件的内容

postgresql - 在 docker-compose 中的容器入口点之后运行脚本

ubuntu - docker -Ubuntu-bash : ping: command not found

git - 2次提交之间的所有提交列表

java - hudson : map SVN credentials to emails

jenkins - 如何限制并行运行的某些管道的数量?

Jenkins 声明式管道 : find out triggering job

docker - vagrant 上的 PHP docker 容器中的 PhpStorm 和 PHPUnit

docker - 将流量重定向到Kubernetes服务中的Tomcat上下文路径

docker - 如何在 jenkins 的 docker 容器中运行 redis?