0

我正在尝试编写一个管道,它首先克隆一个存储库,然后构建一个 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})
                    }
                }
            }
        }
    }
}

但是当我在蓝海中运行这项工作时,我遇到了以下错误。 在此处输入图像描述

我试过用谷歌搜索,但找不到满意的答案。任何帮助表示赞赏。

4

1 回答 1

2

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} .")
           }
        }
    }
于 2019-01-02T11:05:21.797 回答