jenkins 企业微信消息推送 Qy插件 (qyWechatNotification)

安装插件(Qy Wechat Notification)

生成流水线

jenkins 企业微信消息推送 Qy插件 (qyWechatNotification)_第1张图片

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
               
                
            }
        }
    }
    
        post{
        success{
            qyWechatNotification failNotify: true, webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=862dc407-0050-4-8e48-e7e5673811fe'
        }
        failure{
            qyWechatNotification failNotify: true, webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=862dc407-0050-8e48-e7e5673811fe'
        }
    }
    
}

jenkins 企业微信消息推送 Qy插件 (qyWechatNotification)_第2张图片
K8S

pipeline {
  agent {
    kubernetes {
      yaml '''
        apiVersion: v1
        kind: Pod
        metadata:
          labels:
            some-label: jenkins
        spec:
          containers:
          - name: docker
            image: registry-intl.cn-shenzhen.aliyuncs.com/sztest/sz:dockerding
            command:
            - dockerd
            - --host=unix:///var/run/docker.sock
            - --host=tcp://0.0.0.0:8000
            securityContext:
              privileged: true
            tty: true
            
          - name: kubectl
            image: registry.cn-shenzhen.aliyuncs.com/jbjb/csi:kubectl
            command:
            - cat
            tty: true

          - name: agent
            image: registry-intl.cn-shenzhen.aliyuncs.com/sztest/sz:inbound-agent
            command:
            - cat
            tty: true

          - name: node
            image: node:14-alpine
            command:
            - cat
            tty: true            
            volumeMounts:
            - mountPath: "/root/.npm"
              name: "volume-0"
          volumes:
            - name: "volume-0"
              persistentVolumeClaim:
                claimName: "nodejs"  
        '''
   		 }
	 }

environment {

    name="guldalliamce"
    image="registry-intl.cn-shenzhen.aliyuncs.com/sztest/sz:${name}$BUILD_ID"
        }

options{  
timestamps () 
disableConcurrentBuilds() 
buildDiscarder(logRotator(numToKeepStr: '8'))
					}

    stages {
      stage('Get Code && Build Package') {
        steps {  
             container('node') {
          checkout([$class: 'GitSCM', branches: [[name: '*/dev']], extensions: [], userRemoteConfigs: [[credentialsId: 'gitpull', url: 'https://gitc.cc/wutao/guld_alliamce_develop.git']]])
            sh '''
            ls -lh
            
            npm config set registry https://registry.npm.taobao.org
            npm install
            npm run build
            ls -lh
            '''
            
         }
           } 
            }

    stage('Docker Build') {
      steps {
        container('docker') {
   withCredentials([usernamePassword(credentialsId: 'dockers', passwordVariable: 'Password', usernameVariable: 'Username')]) {
                    sh ''' 
                    docker login -u$Username -p$Password registry-intl.cn-shenzhen.aliyuncs.com
                    docker build -t ${image} -f Dockerfile-k8s .   
                    docker push ${image}
                    echo ${image}
                    docker rmi ${image}
                     '''

                }
		        }
      			    }
      				    }
      				    
      stage('Deploy') {
            steps {       
                
                script {
                    sh "sed -i 's#{{image}}#${image}#g' k8s-dev.yaml"
                    sh 'cat k8s-dev.yaml'
                  kubernetesDeploy(configs:"k8s-dev.yaml", kubeconfigId: "kjbs") 
                 qyWechatNotification  webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=862dc3811fe'
            }
               }
                   }
                       }
                       
                
    post{
        success{
            qyWechatNotification failNotify: true, webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=862dc407-050-8e48-e7e5673811fe'
        }
        failure{
            qyWechatNotification failNotify: true, webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=862dc407-050-8e48-e7e5673811fe'
        }
    }
	               
                          }

你可能感兴趣的:(Jenkins,k8s,devops)