- Use Shared Libraries in a dedicated Git repo with vars/, src/, resources/ structure
- Place step functions in vars/: vars/buildDocker.groovy with call() method invoked as buildDocker(image: 'myapp')
- Use src/ for Groovy classes encapsulating complex logic — standard package conventions
- Configure as Global Pipeline Libraries or use @Library('my-lib@main') _ per Jenkinsfile
- Keep functions small and focused — one function per file in vars/
- Use Shared Libraries in a dedicated Git repo with vars/, src/, resources/ structure
- vars/ holds global steps: each .groovy file defines call() invoked by filename
- src/ holds Groovy classes using Java package layout for complex logic
- resources/ stores non-Groovy files — access via libraryResource('templates/deploy.yaml')
- Configure globally or use @Library('my-lib@v2.0') _ to pin versions
- Version with Git tags — never use @main in production Jenkinsfiles
- Keep vars/ functions focused: one responsibility per file; accept Map parameters
- Create standard pipeline template as a vars/ function that generates full pipeline block
- Test with Jenkins Pipeline Unit framework — unit test vars/ and src/
- Jenkinsfiles should be thin orchestration layers calling library functions
- Use @NonCPS on methods with non-serializable objects
- Organize large libraries by domain: core, deploy, notify