请先仔细阅读Jenkins官方对于共享库的文档说明 :扩展共享库

1、新建工程用于存放自定义脚本

github/svn/gitlab 依据你的代码仓库即可,根目录新建  vars目录(自定义脚本存放在此)

2、编写自定义脚本 hello.groovy

def call(args) {
   echo "hello heihei, ${args.name}"
}

3、配置Jenkins全局系统配置

manage Jenkins -> Configure System -> Global Pipeline Libraries 配置页面

 4、Jenkins 项目的pipeline中引入共享库(可以指定仓库版本和具体class) 新建一pipeline类型的job。不使用 groovy沙盒  Pipeline内容如下:

hello([
    name: 'xxx'
])

5、查看构建日志

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐