Jenkins 为Docker代理args使用变量时无法指定标志?
我正试图为我的Docker代理和Jenkins管道装载一个卷。以下是我的文件:Jenkins 为Docker代理args使用变量时无法指定标志?,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我正试图为我的Docker代理和Jenkins管道装载一个卷。以下是我的文件: pipeline { agent none environment { DOCKER_ARGS = '-v /tmp/my-cache:/home/my-cache' } stages { stage('Build') { agent { docker { i
pipeline {
agent none
environment {
DOCKER_ARGS = '-v /tmp/my-cache:/home/my-cache'
}
stages {
stage('Build') {
agent {
docker {
image 'my-image:latest'
args '$DOCKER_ARGS'
}
}
steps {
sh 'ls -la /home'
}
}
}
}
遗憾的是,它无法运行,从pipeline.log文件中可以看到以下内容
java.io.IOException: Failed to run image 'my-image:latest'. Error: docker: Error response from daemon: create /tmp/my-cache: " /tmp/my-cache" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.
但是,以下文件不起作用:
唯一的区别是-v
标志在环境变量外部硬编码
我是詹金斯的新手,所以我很难找到关于这种行为的任何文档。谁能解释一下为什么我不能完全在环境变量中定义Docker代理
args
?我会尝试用双引号替换单引号。不确定解析是否与引号有关。不幸的是,不能这样做,因为$DOCKER_ARGS
将被解释为Groovy变量,而我希望Jenkins直接解析它。
pipeline {
agent none
environment {
DOCKER_ARGS = '/tmp/my-cache:/home/my-cache'
}
stages {
stage('Build') {
agent {
docker {
image 'my-image:latest'
args '-v $DOCKER_ARGS'
}
}
steps {
sh 'ls -la /home'
}
}
}
}