jenkins gitlab webhook 代码提交自动发布

1.jenkins安装webhoook插件

 

 2.配置jenkins流水线

 

 

 

 3.webhook 定义的参数

 

 4.jenkins webhook地址

 

 5.gitee配置webhook地址,地址:http://106.xx.xx.xx/generic-webhook-trigger/invoke?token=demo-maven-service&runOpts=GiteePush  ,并测试一下是否通

 

 

 

 

 

6.jenkins流水线脚本

#!groovy
    
// 引入公共库,jenkins 系统管理--系统配置--Global Pipeline Libraries-- Source Code Management ,【librarl Name】
@Library('gitee-sharelib@master') _
    
// 实例化参数,引入项目目录xx/src/pipeline/build.groovy
def build = new org.pipeline.build()
def tools = new org.pipeline.tools()
    
// 构建类型,构建命令
String buildType = "${env.buildType}"
String buildShell = "${env.buildShell}"
    
// 仓库地址,仓库分支
String srcUrl = "${env.srcUrl}" 
String branchName = "${env.branchName}"


// wehook配置,
if ("${runOpts}" == "GiteePush") {
    branchName = branch - "refs/heads/"

    //currentBuild.description = "Trigger by ${userName} ${branch}" 
    currentBuild.description = "构建用户:${userName} 分支:${branchName}" 
}
    
    
// pipeline
pipeline {
    agent none
    stages {
        stage("CheckOut"){
            agent { node { label 'master'} }
            steps{
                script{
                    echo "当前克隆的仓库为:${srcUrl}"
                    println("当前构建的分支:${branchName}")
                    tools.PrintMes("获取代码","red")
                    //git branch: "${branchName}", credentialsId: 'gitee-sunmmi-passwd', url: "${srcUrl}"
                    checkout([$class: 'GitSCM', branches: [[name: "${branchName}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitee-sunmmi-passwd', url: "${srcUrl}"]]])
                }
            }
        }
        stage("Build") {
            agent { node { label 'master'} }
            steps{
                script{
                    tools.PrintMes("执行打包","red")
                    build.Build(buildType,buildShell)
                }
            }
        }
    }
}

 

posted @ 2020-08-18 10:58  sunmmi  阅读(511)  评论(0)    收藏  举报