【发布时间】:2018-05-10 23:06:11
【问题描述】:
我有多个使用 Jenkinsfiles 从私有注册表检索 docker 映像的管道。我希望能够将 docker 特定信息从文件加载到管道中,这样当 docker 标签或凭据发生更改时,我就不必修改所有 Jenkinsfiles。我尝试使用下面的示例 jenkinsfile 来做到这一点:
def common
pipeline {
agent none
options {
timestamps()
}
stages {
stage('Image fetch') {
steps{
script {
common = load('/home/jenkins/workspace/common/docker_image')
common.fetchImage()
}
}
}
}
使用 docker_image 包含:
def fetchImage() {
agent {
docker {
label “target_node ”
image 'registry-url/image:latest'
alwaysPull true
registryUrl 'https://registry-url’
registryCredentialsId ‘xxxxxxx-xxxxxx-xxxx’
}
}
}
执行管道时出现以下错误:
缺少必需的上下文类 hudson.FilePath 也许你忘了 用提供此功能的步骤包围代码,例如: 节点,dockerNode
如何使用声明性管道做到这一点?
【问题讨论】:
标签: docker groovy jenkins-pipeline