【发布时间】:2021-02-23 22:24:50
【问题描述】:
我在 Jenkins 2.280 中使用具有顺序阶段的声明式管道。
dockerfile的dir参数应该从${params}获取:
pipeline {
agent none
parameters {
choice(name: PLATFORM, choices: ['dir1', 'dir2', ...], description: '')
string(name: FOO, defaultValue: 1001, description: 'Interesting number')
}
stages {
stage('Top') {
agent {
dockerfile {
filename 'Dockerfile'
dir 'platforms/${params.PLATFORM}' // <-- HERE
label 'master'
additionalBuildArgs '--build-arg FOO=${params.FOO}'
args '--mount type=bind,source=/opt/tools,target=/tools,readonly'
}
} // agent
stages {
stage('Checkout') {
steps { checkout scm }
}
stage('Build') {
sh """
// call cmake
// call ninja
"""
}
...
} // stages
} // Top
} // stages
} // pipeline
这似乎总是导致 Java NoSuchFileException:
java.nio.file.NoSuchFileException: /var/jenkins_home/workspace/<ws_name>/platforms/${params.PLATFORM}/Dockerfile
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
如果我将dir 参数硬编码到一个有效的目录名称,那么我会遇到FOO 的问题:
[Pipeline] withEnv
[Pipeline] {
[Pipeline] isUnix
[Pipeline] readFile
[Pipeline] sh
14:18:02 /var/jenkins_home/workspace/<ws_name>@tmp/durable-5884cc09/script.sh: 1: /var/jenkins_home/workspace/<ws_name>@tmp/durable-5884cc09/script.sh: Bad substitution
这两件事怎么办?
有更好的方法吗?
更新:我的问题是管道项目名称中的“空格”。
【问题讨论】:
标签: jenkins dockerfile jenkins-pipeline