zoukankan      html  css  js  c++  java
  • Jenkins Pipeline 带webhook推送

    properties([
        parameters([
            string(name: 'tag', defaultValue: '', description: 'which tag you want to deploy?')
         
        ])
    ])
    
    node() {
        def ip_list = ["10.10.10.11"]
        def app_name = "enterprise-ebank-biz"
        stage('Download code'){
            checkout([$class: 'GitSCM', branches: [[name: "${params.tag}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '57416da9-4867-474b-ba70-8826449f4990', url: 'http://192.168.138.192/byb/enterprise-ebank-service.git']]])
    	}
        
    sh "curl --location --request POST 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d94ecea4-42d6-4197-baae-e9cb66ba20a5' --header 'Content-Type: application/json' --data '{"msgtype": "markdown","markdown": {"content": "环境<font color= \"warning\"  >${params.tag}</font>,正在发布,请相关同学注意。\n >服务名:<font color=\"comment\">${app_name}</font> \n>进度:<font color=\"comment\">发布中</font> \n>ip:<font color=\"comment\">${ip_list}</font>"}}'"
    
        stage('compile'){
            // 编译失败自动退出
            sh '/data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/3.5.0/bin/mvn clean deploy -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}/${app_name}/target/${app_name}-1.0.0-SNAPSHOT.jar dest=/data/app/${app_name}/${app_name}.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/${app_name}/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/${app_name}/scripts/start.sh' -u user01"
                }
            }
            sh "curl --location --request POST 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d94ecea4-42d6-4197-baae-e9cb66ba20a5' --header 'Content-Type: application/json' --data '{"msgtype": "markdown","markdown": {"content": "环境<font color= \"warning\"  >test</font>,发布完成。\n >服务名:<font color=\"comment\">enterprise-ebank-service</font> \n>进度:<font color=\"comment\">发布完成</font> \n>ip:<font color=\"comment\">${ip_list}</font>"}}'"
    
            println "发布" + ip  + "成功" 
        }
        
            
    } 
    

      

  • 相关阅读:
    【CSS】4种CSS方法设置元素垂直水平居中
    js数据类型:引用和5种基本数据类型
    iOS——CALayer的shadow无效问题
    iOS——自定义Segue实现总结
    iOS动画
    iOS——Command-Line 查看当前SDK版本并修改默认SDK版本
    iOS——Swift开发中的单例设计模式(摘译,非原创)
    Windows Phone 8 解锁提示IpOverUsbSvc问题——IpOverUsbEnum返回No connected partners found解决方案
    Windows 8.1 开发过程中遇到的小问题(2)
    Windows 8.1 开发过程中遇到的小问题
  • 原文地址:https://www.cnblogs.com/NGU-PX/p/14188254.html
Copyright © 2011-2022 走看看