hubei前端jenkins

pipeline {
    // 选择标签为maven的模板
    agent { node { label "node" } }
    options {
        buildDiscarder(logRotator(numToKeepStr: '3'))
    }
    parameters {
          gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH', type: 'PT_BRANCH'
          choice choices: ['hubei'], description: '请选择需要发布的名称空间', name: 'NS_NAME'
    }
	stages{
	  stage('代码拉取') {
        steps {
             script {
                  checkout scmGit(branches: [[name: '${BRANCH}']], extensions: [], userRemoteConfigs: [[credentialsId: 'aliyun', url: 'https://codeup.aliyun.com/glr/cems/cems-frontend/show.git']])
                  env.BUILD_TAG = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
                  env.APP_NAME = sh(returnStdout: true, script: "git config -l|git config -l|grep remote.origin.url|awk -F/ '{print \$NF}'|cut -d. -f1").trim()
             }
          }
        }
      stage('代码编译') {
        steps {
             script {
                  sh "npm config set registry http://10.33.22.19:8081/repository/npm-group/"
                  sh "npm install --unsafe-perm"
                  sh "npm run build"
             }
          }
        }
      stage('镜像构建、上传') {
		steps {
		     script {
                withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'dockerHubPassword',usernameVariable: 'dockerHubUser')]) {
                sh "docker login -u ${dockerHubUser} -p ${dockerHubPassword} harbor.glroad.com:8800"
                sh "sed -i \"s/172.21.0.13:20003/cems-gateway-svc/g\" nginx.default.conf"
				sh "docker build -t harbor.glroad.com:8800/cems/${JOB_NAME}:${BUILD_TAG} ."
                sh "docker push harbor.glroad.com:8800/cems/${JOB_NAME}:${BUILD_TAG}"
		     }
		   }
	     }
	   }
      stage('部署&更新') {
        steps {
            sh'''
                   sed -i \"s/<APP_NAME>/${JOB_NAME}/g\" k8s-cems-frontend-show.yaml
                   sed -i \"s/<BUILD_TAG>/${BUILD_TAG}/g\" k8s-cems-frontend-show.yaml
                   sed -i \"s/<NS_NAME>/${NS_NAME}/g\" k8s-cems-frontend-show.yaml
                   kubectl apply -f k8s-cems-frontend-show.yaml --record
                   echo "http://10.33.22.37:`kubectl get svc -n dev|grep ${JOB_NAME}-svc|awk -F':' '{print$2}'|awk -F'/TCP' '{print $1}'`/show"
            '''
         }
       }
    }
}

  

posted @ 2024-03-13 16:10  beawh  阅读(3)  评论(0编辑  收藏  举报