zoukankan      html  css  js  c++  java
  • Jenkins自动发布Pipeline脚本

    properties([
        parameters([
            string(name: 'tag', defaultValue: '', description: 'which tag you want to deploy?')
         
        ])
    ])
    
    node() {
        def ip_list = ["10.10.10.2","10.10.10.3"]
        def app_name = "mobile-biz-server"
    
        stage('Download code'){
            checkout([$class: 'GitSCM', branches: [[name: "${params.tag}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '57416da9-4867-474b-ba70-8826449f4990', url: 'http://gitlab.xxx.com/byb/mobile-biz.git']]])
        }
    
        stage('compile'){
            // 编译失败自动退出
            sh '/data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/3.5.0/bin/mvn deploy -f ../byb-mobile-gateway-test/pom.xml  --update-snapshots -DskipTests=true'
            sh '/data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/3.5.0/bin/mvn clean package -U  -Dmaven.test.skip=true'
        }
    
        // Loop through all parallel branched stage names
        ip_list.each{ip->
    
            stage('同步jar包和配置文件') {
                withCredentials([sshUserPrivateKey(credentialsId: '8d3e56e8-57c8-44a3-81e7-30a450310836', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'username')]) {
                   sh "ansible  all -i ${ip}, -e ansible_ssh_user=$username -e ansible_ssh_private_key_file=$identity -m file -a 'path=/data/app/${app_name} state=directory owner=user01 group=user01 mode=0755' -u user01" 
    
                   sh "ansible  all -i ${ip}, -e ansible_ssh_user=$username -e ansible_ssh_private_key_file=$identity -m copy -a 'src=${JENKINS_HOME}/workspace/${JOB_NAME}/mobile-biz-server/target/mobile-biz-server-1.0.0-SNAPSHOT.jar dest=/data/app/mobile-biz-server/mobile-biz.jar owner=user01 group=user01 mode=0755 backup=yes' -u user01"
                }
            }
    
            stage('关闭与启动服务'){
                withCredentials([sshUserPrivateKey(credentialsId: '8d3e56e8-57c8-44a3-81e7-30a450310836', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'username')]) {
                   sh "ansible  all -i ${ip}, -e ansible_ssh_user=$username -e ansible_ssh_private_key_file=$identity -m shell -a 'sh /data/app/mobile-biz-server/scripts/stop.sh' -u user01"
                   sh "ansible  all -i ${ip}, -e ansible_ssh_user=$username -e ansible_ssh_private_key_file=$identity -m shell -a 'sh /data/app/mobile-biz-server/scripts/start.sh' -u user01"
                }
            }
            println "发布" + ip  + "成功" 
        }
        
    }
      
  • 相关阅读:
    理解MySQL——索引与优化(转)
    C# 实现3Des加密 解密
    des加密解密源码 C# key值问题
    深入浅出mysql优化--一篇博客让你精通mysql优化策略--中
    深入浅出mysql优化--一篇博客让你精通mysql优化策略--上
    深入浅出mysql优化--了解mysql常用索引结构
    从零开始了解多线程 之 深入浅出AQS -- 下(Tools&CountDownLatch&CyclicBarrier&Semaphore)
    从零开始了解多线程 之 深入浅出AQS -- 上
    从零开始了解多线程知识之开始篇目 -- jvm&volatile
    利用doxygen提高源代码阅读效率
  • 原文地址:https://www.cnblogs.com/NGU-PX/p/14155906.html
Copyright © 2011-2022 走看看