jenkins共享库代码如何放在安装目录,请给出具体案例
时间: 2023-12-29 20:03:44 浏览: 208
Jenkins共享库代码可以放在Jenkins安装目录下的vars文件夹中。具体操作步骤如下:
1. 打开Jenkins主界面,点击"系统管理",再点击"系统设置",找到"Global Pipeline Libraries"一栏。
2. 点击"Add"按钮,填写"Name"和"Default Version",其中"Name"是库的名称,"Default Version"是库的默认版本,然后点击"Save"按钮。
3. 在Jenkins安装目录下的vars文件夹中创建与库名称相同的文件夹,并将库的代码放入该文件夹中。例如,如果库名称为"my-library",则在vars文件夹中创建一个名为"my-library"的文件夹,并将库的代码放入其中。
4. 在Jenkinsfile中通过@Library注解来引用该库。例如:
```
@Library('my-library') _
```
这样,就可以在Jenkinsfile中使用该库中的函数和变量了。
注意事项:
1. 如果Jenkins安装目录发生变化,共享库代码也需要相应地进行移动或更新。
2. 共享库代码必须符合Jenkins共享库的结构和规范,否则会导致引用失败。
阅读全文
相关推荐


















