使用动态Docker代理时如何构建Docker映像?

时间:2019-10-16 10:10:32

标签: docker jenkins jenkins-pipeline jenkins-slave

将docker作为jenkins代理运行时如何构建docker镜像。

我试图了解我们构建docker映像的不同方式

Jenkins安装在虚拟机-centos 7上,与docker安装在同一台计算机上。

import { LocalStorage } from "quasar";

export default ({ router }) => {
router.beforeEach((to, from, next) => {
let loggedIn = LocalStorage.getItem("loggedIn");
if (!loggedIn && to.path !== "/signin") {
  next("/signin");
} else {
  next();
}
pipeline {
    agent {
        docker {
            image 'maven:3.6.2-jdk-11'
        }
    }
    environment {
        IMAGE_NAME=readMavenPom().getArtifactId()
        BUILD_NUMBER="${env.BUILD_NUMBER}"
        GITLAB_URL="xxxx"
        IMAGE_VERSION=readMavenPom().getVersion()
        GIT_URL="xxxx"
        GIT_CRED_ID="xxxx"
        DOCKER_REPOURL="xxxx"
    }
    options {
        timestamps()
    }
    stages {
        stage ('Checkout') {
            steps {
                echo 'Build Started ...'
                checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/jenkins_build']], browser: [$class: 'GitLab', repoUrl: "${GITLAB_URL}", version: '11.10'], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${GIT_CRED_ID}", url: "${GIT_URL}"]]]
                configFileProvider([configFile(fileId: '392b1fe8-8ccd-4b8a-a73b-1d745a6bd03d', variable: MAVEN_GLOBAL_SETTINGS{
                    sh 'mvn -gs $MAVEN_GLOBAL_SETTINGS clean package '
                }
            }
        }
        stage('Publish') {
            steps {
                echo 'Build and Deploy to Nexus ...'
                withDockerRegistry(credentialsId: 'nexus_docker_creds', url: 'xxxxxx') {
                    sh '''
            docker --version
                        docker build -t "${DOCKER_REPOURL}"/"${IMAGE_NAME}":"${IMAGE_VERSION}"
                    '''
                }
            }
        }
    }
}

0 个答案:

没有答案