Jenkins CICD pipeline

def label = "master"
 
node(label) {
   stage('Checkout JavaSrc') {
       sh "rm ./* -fr"
      git credentialsId: 'gitaccount', url: "https://gitee.com/yangxlgit/guestbook.git", branch: "master"
   }
  stage('build jar ') {
           sh "/usr/bin/mvn clean package"
   }
   
  stage('upload jar ') {
           sh "scp target/hello-world-1.0-SNAPSHOT.jar root@172.16.1.10:/root/"
   }
   
   stage('checkout dockerfile') {
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'dc-dockerfile']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitlab-for-ci-cd', url: 'http://gitlab.product.co-mall:10080/jci/jci-dockerfile.git']]])
        sh "cp -f ./dc-dockerfile/test/microservice/Dockerfile-MicroService ./Dockerfile"
        sh "cp -f ./dc-dockerfile/test/microservice/entrypoint.sh ./entrypoint.sh"
        sh "sed -i 's#target/.*jar #'`ls '${Jar_dir}'/*.jar`' #g' Dockerfile"
        sh "sed -i 's#FROM.*#FROM harbor.product.co-mall/library/centos-tomcat8:latest#g' Dockerfile"
        sh "sed -i 's#EXPOSE.*#EXPOSE '$app_port'#g' Dockerfile"
        sh "cat Dockerfile"
    }
    stage('build image ') {
        withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'harbor-for-ci-cd',
        usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
        sh  "docker login -u ${USERNAME} -p ${PASSWORD} harbor.product.co-mall"
        sh  "docker build -t harbor.product.co-mall/project_jci/${project}:${image_tag} ."
        def testImage = docker.image("harbor.product.co-mall/project_jci/${project}:${image_tag}")
        testImage.push()
        }
    }
}
 

上一篇:「笔记整理」D2前端技术论坛: 揭秘TC39: ES2020 和 ES2021


下一篇:Centos双网卡冗余绑定