我想使用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 >
}
}
}
}
我正在挣扎的是如何从"构建人工制品"阶段使用的容器中传递文件到"部署工件"中使用的容器,据我所知,据我所知,stash
将无法跨容器工作,除非有人有其他经验。
根据詹金斯文档,您可以使用args参数来指定声明管道语法的卷:
pipeline {
agent {
docker {
image 'maven:3-alpine'
args '-v $HOME/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B'
}
}
}
}
但是,我想知道是否有一个更优雅的解决方案,不涉及传递卷。
规定工件不太大,您可以使用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'
}
}
}
}
有关详细信息,请参见藏匿文档
您可以使用" docker run"。
这里更详细:
https://damnhandy.com/2016/03/06/creating-containerized-build-environments-with-the-the-the-the--jenkins-pipeline-plugin-plugin-plugin-and-docker-well-well-al-most/