我正在尝试编写一个管道,该管道首先克隆一个存储库,然后构建一个docker映像,然后将docker映像推送到docker hub。以下是我的詹金斯文件。
pipeline {
agent { dockerfile true }
environment {
APPLICATION = 'connect'
ENVIRONMENT = 'dev'
BUILD_VERSION = '0.9.5'
MAINTAINER_NAME = 'Shoaib'
MAINTAINER_EMAIL = 'shoaib@email.com'
BUILD_DOCKER_REPO = repo1/images'
DOCKER_IMAGE_TAG = 'repo1/images:connect_dev_0.9.5'
}
stages {
stage('clone repository') {
steps {
checkout Jenkins-Integration
}
}
stage('Build Image') {
steps {
image = docker.build("-f Dockerfile.local", "--no-cache", "-t ${DOCKER_IMAGE_TAG}", "--build-arg envior=${ENVIRONMENT} .", "--build-arg build_version=${BUILD_VERSION} .", "--build-arg maintainer_name=${MAINTAINER_NAME} .", "--build-arg maintainaer_email=${MAINTAINER_EMAIL} .")
}
}
stage('Deploy') {
steps {
script {
docker.withRegistry('https://registry.example.com', 'docker-hub-credentials') {
image.push(${DOCKER_IMAGE_TAG})
}
}
}
}
}
}
我尝试使用Google搜索,但找不到满意的答案。任何帮助表示赞赏。
答案 0 :(得分:1)
将以下阶段的docker.build
放入script
中,如下所示:
stage('Build Image') {
steps {
script {
def image = docker.build("-f Dockerfile.local", "--no-cache", "-t ${DOCKER_IMAGE_TAG}", "--build-arg envior=${ENVIRONMENT}", "--build-arg build_version=${BUILD_VERSION}", "--build-arg maintainer_name=${MAINTAINER_NAME}", "--build-arg maintainaer_email=${MAINTAINER_EMAIL} .")
}
}
}