我刚接触Jenkins ....
我正在尝试使用声明性Jenkins文件自动生成图像(隐藏在回购中)。我发现文档令人困惑(充其量)。简单地说,我如何转换以下脚本示例(来自the docs)
node {
checkout scm
def customImage = docker.build("my-image:${env.BUILD_ID}")
customImage.push()
}
到声明性Jenkins文件....
答案 0 :(得分:18)
您可以use scripted pipeline blocks in a declarative pipeline作为解决方法
pipeline {
agent any
stages {
stage('Build image') {
steps {
echo 'Starting to build docker image'
script {
def customImage = docker.build("my-image:${env.BUILD_ID}")
customImage.push()
}
}
}
}
}
答案 1 :(得分:1)
我正在使用以下方法:
steps {
withDockerRegistry([ credentialsId: "<CREDENTIALS_ID>", url: "<PRIVATE_REGISTRY_URL>" ]) {
// following commands will be executed within logged docker registry
sh 'docker push <image>'
}
}
位置: