docker - Jenkins Docker Declarative .withRun
问题描述
I am using the declarative format for pipeline files and running inside of a docker container that is defined using a Dockerfile in my project's root directory.
My Jenkinsfile looks like this:
pipeline {
agent {
dockerfile {
additionalBuildArgs '--network host'
}
}
stages {
stage('Test') {
steps {
sh 'pytest --version'
}
}
}
I would like to pass additional arguments to the docker run command similar to this question ... How to pass docker container arguments when running the image in a Jenkinsfile
Is it possible to do that in the declarative pipeline format, or should I switch?
Edit:
This is essentially the equivalent of what I am trying to do in non-declarative:
node {
def pytestImage = docker.build('pytest-image:latest', '--network host .')
pytestImage.inside('--network=host') {
sh 'pytest --version'
// other commands ...
}
}
解决方案
您可以将args
选项添加到您的dockerfile
. 它将参数直接传递给docker run
调用:
pipeline {
agent {
dockerfile {
additionalBuildArgs '--network host'
args '--network=host'
}
}
stages {
stage('Test') {
steps {
sh 'pytest --version'
}
}
}
更多信息在这里
推荐阅读
- css - 通过打字稿更改按钮单击时的svg颜色
- angularjs - ng-repeat 的每个元素的特定颜色
- mysql - 如何在变量中设置MySQL参数多个值
- authentication - 我可以使用 OAuth 对受信任的客户端(移动应用程序)进行身份验证吗?
- angular - 如何检查任何模型属性是否为空?
- java - 为什么不支持不同返回类型的重载
- mysql - TYPO3 9 LTS 类型转换错误在 mysql 时间字段上用于 TCA 类型输入/dbType 节省时间的空字段
- javascript - 如何在代码(node.js)中处理“进程内存不足后返回的 API 致命错误处理程序”?
- javascript - 在执行上下文的创建阶段如何加载 javascript 对象和 javascript 函数?
- ios - 如何在 iOS 中创建一个旋转的彩虹色圈