jenkins学习笔记之六:共享库方式集成构建工具

一、新建library文件 build.groovy 

package org.devops

// 构建类型

def Build(buildType,buildShell){
    
    // M3 ANT等值都是配置相关全局工具是定义的名称
    def buildTools = ["mvn":"M3","ant":"ANT","gradle":"GRADLE","npm":"NPM"]
    
    println("当前选择的构建类型为:${buildType}")
    buildHome = tool buildTools[buildType]
    
    sh "${buildHome}/bin/${buildType}  ${buildShell}"

}

2.新建一个jenkins CI文件

#!groovy

@Library('jenkinslibrary@master') _

def build = new org.devops.build()

// buildType  buildShell 为选项参数名称
String buildType = "${env.buildType}"
String buildShell = "${env.buildShell}"

pipeline {
    agent any
    
    stages {
        stage("build"){
            steps{
                script {
                    println(buildType)
                    println(buildShell)
                    build.Build(buildType,buildShell)
                }
            }
        }
    }
}

3.配置pipeline

3.1 新增选项参数

注意选项名称和值,需要和jenkinsfile及sharelibrary中保持一致

 3.2  指定jenkinsfile路径

 3.3 验证

 

posted @ 2023-02-27 00:16  百衲本  阅读(116)  评论(0编辑  收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码