跳转到主要内容

jenkins&&docker安装

核心点是3个主要挂载的,socker.sock需要根据情况定,需要以root身份运行




version: '3'
services:
  jenkins:
    image: harbor.iovhm.com/hub/jenkins/jenkins:2.477-jdk17
    container_name: jenkins
    restart: always
    privileged: true
    user: root
    ports:
      - "8080:8080"
    volumes:
      - ./jenkins_home:/var/jenkins_home
      - ./m2:/root/.m2
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker



springboot maven pipline

pipeline {
    agent any

    environment {
        PROJECT_NAME    ="springboot-demo"
        PROJECT_NS      ="vp-whdev"
        DOCKER_REGISTRY ="swr.cn-south-1.myhuaweicloud.com"
        
    }
    
    parameters {
        string(name:"VERSION",defaultValue:"v1",description:"版本号")
        string(name:"IMAGE_TAG",defaultValue:"latest",description:"镜像的tag")
    }

    tools {
        // Install the Maven version configured as "M3" and add it to the path.
        maven "M3"
    }

    stages {
        stage('Build') {
            steps {
                
                // Get some code from a gitlab
                git branch: 'release', credentialsId: '10b8bc82-8b90-4fbb-9f55-d7e3126b35c0', url: 'https://git.whdev.vpclub.cn:10081/park-weihai/backend-api.git'

                // Run Maven on a Unix agent.
                // sh "mvn clean compile package -f ./renren-cloud-tenant/pom.xml"
                dir("renren-cloud-tenant/"){
                     sh "mvn clean compile package"
                }
            }
        }
        
        stage("docker"){
            steps{
                dir('./renren-cloud-tenant/park-admin/park-admin-server/') {
                    
                    withCredentials([usernamePassword(credentialsId: 'docker-huaweicloud', passwordVariable: 'docker_password', usernameVariable: 'docker_username')]) {
                        
                        sh '''
                            docker login -u ${docker_username} -p ${docker_password} ${DOCKER_REGISTRY}
                            docker build -t ${DOCKER_REGISTRY}/${PROJECT_NS}/${PROJECT_NAME}:${VERSION}-${IMAGE_TAG} .
                            docker push ${DOCKER_REGISTRY}/${PROJECT_NS}/${PROJECT_NAME}:${VERSION}-${IMAGE_TAG}
                        '''
                    }
                }
            }
        }
    }
}