• 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  + "成功" 
        }
        
    }
      
  • 相关阅读:
    时间序列理论专题之二 时间序列的表达
    Ado.net Entity FrameWork的性能问题
    时间序列专题之三 时间序列的分段线性表示
    Tfs 2010使用小技巧
    时间序列理论专题之一 前言
    绝大多数新技术的学习,都是浪费生命
    Tfs2010简体中文版:翻译永远是问题
    MSsql 查询时默认是不区分大小写。 可以用语句强制sql语句查询时区分大小写 狼
    将.NET dll注册到GAC(Global Assembly Cache)中 狼
    js重载 狼
  • 原文地址:https://www.cnblogs.com/NGU-PX/p/14155906.html
Copyright © 2020-2023  润新知