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  + "成功" 
        }
        
            
    } 
    

      

  • 相关阅读:
    Ubuntu 20.04下EasyConnect兼容性问题临时解决方案
    Ubuntu 20.04 LTS安装搜狗输入法,只需三条命令,还能自动更新
    Java笔记: 继承成员覆盖和隐藏
    Java扫雷游戏: JMine
    Emacs: 设置窗口标题格式
    Java笔记: protected的真正含义
    Java笔记: 初始化块
    Ubuntu跨版本安装软件
    百度编辑器 Ueditor 增加字体
    AspCms 升级百度编辑器
  • 原文地址:https://www.cnblogs.com/NGU-PX/p/14188254.html
Copyright © 2011-2022 走看看