Jenkins扩展shared-library进行企业微信消息推送

59 篇文章 3 订阅
  • wxput.groovy
package org.devops

def test_success() {
    sh '''
   curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='$webhook'' \
   -H 'Content-Type: application/json' \
   -d '
   {
        "msgtype": "markdown",
         "markdown": {      
            "content": "#### 构建成功 ✅:'$name'项目!
            >### 持续时间:'$times'
            >### 任务:#'$task'"
         }
        }'
            '''
}
def test_failure(){
                sh '''
   curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='$webhook'' \
   -H 'Content-Type: application/json' \
   -d '
   {
        "msgtype": "markdown",
         "markdown": {      
            "content": "#### 构建失败 ❌'$name'项目! 
             >### 持续时间:'$times'
             >### 任务:#'$task'"
             
         }
        }'
            '''
}
  • jenkinfile
@Library ("jr-shared-library") _

def wxput = new org.devops.wxput()

pipeline {
    agent any

 environment {

    name="wxput_test"
    times="${currentBuild.duration}"
    task="${BUILD_ID}"
    logs="${ChangeLog}"
    webhook="e20f4185-817c-4838-b92e-c3fa6f9c3f5"
        }

    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
            }
        }
    }

post { 
  success {
       script{
         wxput.test_success()   
             }
        }
        failure {
            
        script{
            wxput.test_failure()
            
              }
            }
        }    
}

在这里插入图片描述

  • 动态salve使用
@Library ("jr-shared-library") _

def docker_test_bui = new org.devops.docker_test_bui()
def deploy_test = new org.devops.deploy_test()
def wxput = new org.devops.wxput()

pipeline {
    
   environment {
    name="salary-manager"
    image="/libary/jr-prod-01:${name}$BUILD_ID"
    times="${currentBuild.duration}"
    task="${BUILD_ID}"
    logs="${ChangeLog}"
    webhook="e20f4185-817c-4838-b92e-c3fa6f9c3f5"
        }
        
    agent { 
        
     kubernetes {
       inheritFrom 'maven-test'
      }
    }   

    options{ 
      timestamps ()
      disableConcurrentBuilds () 
      buildDiscarder(logRotator(numToKeepStr: '10'))       
    }
    
    stages {
      stage('Get Code') {
        steps {  
  checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'vip', url: 'https://wwwq.q..ocm/SS-salary/alary-manager.git']]])
         }
           }

        stage('Java-build') {
            steps {       
                container('maven36'){
                    sh 'mvn install -DskipTests'
                  
                
                }
            }
        }
        
      stage('Docker-build') {
            steps {       
                container('docker'){
                 script {
                    docker_test_bui.docker_bui()
                }
         
            }
        }
      }
      
      stage('Deploy....') {
        steps {       
        container('kubectl'){
          script {
             deploy_test.test_kue()
               }
                 }
                    }
                        }

                            }
                              post { 
                                 success {
                                  script{
                               wxput.test_success()   
                                     }
                                }
                              failure {        
                                    script{
                                    wxput.test_failure()
            
                                           }
                                          }
                                         }
                                        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值