所以,我有一个完全在 Docker 容器内构建的管道作业。使用的 Docker 镜像是在构建之前从本地存储库中提取的,并且具有运行我的项目所需的几乎所有依赖项。
问题是我需要一个选项来定义卷以将 Mound 从主机绑定到容器,以便我可以使用主机系统上可用但不在容器中的工具执行一些分析。
有没有办法从 Jenkinsfile(管道脚本)内部做到这一点?
我不完全清楚这是否是你的意思。但如果不是。让我知道,我会试着弄清楚。
我对从主机安装到容器的理解是将 Jenkins 工作区的内容安装在容器内。
例如在这个管道中:
pipeline {
agent { node { label 'xxx' } }
options {
buildDiscarder(logRotator(numToKeepStr: '3', artifactNumToKeepStr: '1'))
}
stages {
stage('add file') {
steps {
sh 'touch myfile.txt'
sh 'ls'
}
}
stage('Deploy') {
agent {
docker {
image 'lvthillo/aws-cli'
args '-v $WORKSPACE:/project'
reuseNode true
}
}
steps {
sh 'ls'
sh 'aws --version'
}
}
}
post {
always {
cleanWs()
}
}
}
在第一阶段,我只是向工作区添加一个文件。就在詹金斯。与 Docker 无关。
在第二阶段,我启动了一个包含 aws CLI 的 docker 容器(我们的 jenkins slaves 上没有安装这个)。我们将启动容器并将工作区安装在/project
我的容器文件夹中。现在我可以执行 AWS CLI 命令并且我可以访问文本文件。在下一阶段(不在管道中),您可以在不同的容器或 jenkins slave 本身中再次使用该文件。
输出:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (add file)
[Pipeline] sh
[test] Running shell script
+ touch myfile.txt
[Pipeline] sh
[test] Running shell script
+ ls
myfile.txt
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] getContext
[Pipeline] sh
[test] Running shell script
+ docker inspect -f . lvthillo/aws-cli
.
[Pipeline] withDockerContainer
FJ Arch Slave 7 does not seem to be running inside a container
$ docker run -t -d -u 201:201 -v $WORKSPACE:/project -w ... lvthillo/aws-cli cat
$ docker top xx -eo pid,comm
[Pipeline] {
[Pipeline] sh
[test] Running shell script
+ ls
myfile.txt
[Pipeline] sh
[test] Running shell script
+ aws --version
aws-cli/1.14.57 Python/2.7.14 Linux/4.9.78-1-lts botocore/1.9.10
[Pipeline] }
$ docker stop --time=1 3652bf94e933cbc888def1eeaf89e1cf24554408f9e4421fabfd660012a53365
$ docker rm -f 3652bf94e933cbc888def1eeaf89e1cf24554408f9e4421fabfd660012a53365
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] cleanWs
[WS-CLEANUP] Deleting project workspace...[WS-CLEANUP] done
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
在您的情况下,您可以将数据安装在容器中。执行这些操作,在稍后阶段,您可以对 jenkins slave 本身的代码进行分析(没有 docker)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句