在Jenkins声明式pipe道中将一个人工制品复制到另一个人员身上

我想使用Jenkins声明式pipe道和代理语法来构build我想要部署到侧面汽车容器的制造品,如下面的伪代码所示:

pipeline { agent none stages { stage('Build Artefact') { agent { docker 'build-agent' } steps { < I want to create the artefact to deploy to a side car container here > } } stage('Deploy Artefact') { agent { docker 'side-car' } steps { < I want to deploy the artefact created in the previous stage here > } } } } 

我正在努力解决的是如何将“Build Artefact”阶段使用的容器中的文件传递到“Deploy Artefact”中使用的容器,据我所知, stash不会跨容器工作,除非有人否则有经验。

根据Jenkins文档,您可以使用args参数为声明式pipe道语法指定一个卷:

 pipeline { agent { docker { image 'maven:3-alpine' args '-v $HOME/.m2:/root/.m2' } } stages { stage('Build') { steps { sh 'mvn -B' } } } } 

但是,我想知道是否有一个更优雅的解决scheme,不涉及通过卷。

在使用“docker run”时,可以使用-v参数将物理jenkins目录(例如自己的作业工作区)映射到逻辑泊坞窗卷。

这里是更详细的:

https://damnhandy.com/2016/03/06/creating-containerized-build-environments-with-the-jenkins-pipeline-plugin-and-docker-well-almost/