我想使用Jenkins声明性管道和代理语法来构建一个我想要部署到侧面汽车容器的人工制品,如下面的伪代码所示:
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参数为声明性管道语法指定卷:
pipeline {
agent {
docker {
image 'maven:3-alpine'
args '-v $HOME/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B'
}
}
}
}
但是,我想知道是否有一个更优雅的解决方案,不涉及传递卷。
答案 0 :(得分:1)
假设工件不是太大,可以使用stash
指令在不同容器中的各个阶段之间传递某些文件。
pipeline {
agent none
stages {
stage('Build Artefact') {
agent { docker 'build-agent' }
steps {
sh 'make'
stash includes: 'myartefact', name: 'ARTEFACT'
}
}
stage('Deploy Artefact') {
agent { docker 'side-car' }
steps {
unstash 'ARTEFACT'
sh 'deploy.sh'
}
}
}
}
有关详细信息,请参见stash Documentation
答案 1 :(得分:0)
使用“docker run”时,可以使用-v参数将逻辑docker卷映射到物理jenkins目录(例如,自己的作业工作空间)。
以下是更详细的信息: