# jenkins-shared-lib **Repository Path**: LingJianCode/jenkins-shared-lib ## Basic Information - **Project Name**: jenkins-shared-lib - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-22 - **Last Updated**: 2025-08-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Jenkins Shared Library 示例 ## 使用方法 ### 1. Jenkins 系统配置 在 Jenkins -> 系统管理 -> 全局库(Global Trusted Pipeline Libraries),添加: - 名称: `jenkins-shared-lib` (这里的名称与jenkinsfile引用关联) ### 2. 在 Jenkinsfile 中引用 见[study01.groovy](jenkinsfile/study01.groovy) # 目录区别 ## 📂 vars/ 目录 - 作用:定义 全局可调用的 Pipeline 步骤, 存放pipeline中使用的函数,可以全局使用且无须导入。 - 特点: - 每个文件必须和函数同名,例如 vars/buildApp.groovy → buildApp() - 在 Jenkinsfile 里直接用方法名调用,不需要 import - 可以直接使用Jenkins其他插件 ## Global Vars Documentation `/job/test/pipeline-syntax/globals` Each of the global variables (helper functions) has its own documentation (corresponding *.txt file). You can access these documentation on the Global Variable Reference link on the navigation sidebar of pipeline jobs that imported this shared library. Note that as per Jenkins documentation this is only visible after one successful run of the pipeline job for the documentation to be generated. The documentation is in (.txt) file format and contains HTML. ## 📂 src/org/example/ 目录 - 作用:写成 Groovy 类,可以像 Java 包一样组织。存放共享代码,例如类和辅助函数,需要先导入才能在pipeline中使用。 - 特点: - 目录结构必须符合包路径,例如 src/org/example/Utils.groovy → package org.example - 在 Jenkinsfile 或 vars/ 中需要 import 才能使用 - 不能直接使用Jenkins的插件,在 src/ 的普通 Groovy 类里调用插件步骤,需要通过 Pipeline 脚本上下文对象(一般传 this)调用。