/cicd-tooling-skills:jenkins-centralized-shared-libraryfrom cicd-tooling-skills
Designs and maintains a centralized Jenkins Shared Library (vars/ + src/ layout) so repos use a thin Jenkinsfile calling shared pipeline functions, eliminating duplicated logic.
Ships in cicd-tooling-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
When ten, fifty, or a hundred repos each carry their own hand-written
Jenkinsfile (jenkins-declarative-pipeline-per-repo),
a single change — a new required security scan, a registry migration, a
Groovy bugfix — has to be copy-pasted into every repo, drifts immediately,
and is untestable in isolation. A Jenkins Shared Library solves this by
hosting the real pipeline logic in one Git repository (vars/ for
callable global steps, src/ for supporting Groovy classes), registered
once with the Jenkins controller, so every consuming repo's Jenkinsfile
shrinks to a few lines that call one shared function with parameters. This
skill covers the shared library's structure, how a thin per-repo
Jenkinsfile consumes it, and how to version the library so a change
doesn't break every pipeline simultaneously.
vars/*.groovy) or
a breaking change that must be versioned so consumers can opt in
gradually.main/master and consumers pinned to a floating ref.jenkins-shared-library or pipeline-library), separate from any
consumer application repo.Name (e.g. shared-lib), a default version, and either
"Load implicitly" off (recommended — require explicit @Library) or on.v1.4.0, or a floating main for early adoption only).src/ classes — see
jenkins-groovy-scripting-best-practices
for sandboxing and testing guidance specific to this code.Lay out the library repo in the required structure — Jenkins expects exactly these top-level directories:
(root)
├── vars/
│ ├── standardPipeline.groovy # callable as standardPipeline(...)
│ └── standardPipeline.txt # optional: help text shown in Jenkins UI
├── src/
│ └── org/example/pipeline/
│ ├── DeployTarget.groovy # supporting classes
│ └── Notifier.groovy
└── resources/
└── org/example/pipeline/
└── deploy-template.yaml # static files loaded via libraryResource()
Write the global step in vars/. A vars/<name>.groovy file's
call() method is what a consuming Jenkinsfile invokes as <name>(...):
// vars/standardPipeline.groovy
def call(Map config = [:]) {
pipeline {
agent { label config.agentLabel ?: 'linux-x64' }
options {
timeout(time: config.timeoutMinutes ?: 30, unit: 'MINUTES')
}
stages {
stage('Build') {
steps { sh config.buildCommand ?: 'make build' }
}
stage('Test') {
steps { sh config.testCommand ?: 'make test' }
}
stage('Deploy') {
when { branch config.deployBranch ?: 'main' }
steps {
script {
org.example.pipeline.Notifier.notifyStart(this, config.serviceName)
}
sh "make deploy TARGET=${config.deployTarget ?: 'staging'}"
}
}
}
post {
failure {
script {
org.example.pipeline.Notifier.notifyFailure(this, config.serviceName)
}
}
}
}
}
Put reusable, testable logic in src/ classes, not scattered across
multiple vars/*.groovy files — this is ordinary Groovy/Java-style code
and can be unit tested independently of a running Jenkins instance:
// src/org/example/pipeline/Notifier.groovy
package org.example.pipeline
class Notifier implements Serializable {
static void notifyFailure(script, String serviceName) {
script.slackSend(channel: '#builds', color: 'danger',
message: "FAILED: ${serviceName} — ${script.env.BUILD_URL}")
}
static void notifyStart(script, String serviceName) {
script.echo "Deploying ${serviceName}..."
}
}
Passing this/script explicitly (rather than relying on an implicit
global steps binding) keeps src/ classes usable and unit-testable
outside the Jenkins CPS runtime — see
jenkins-groovy-scripting-best-practices.
Consume the library from a thin per-repo Jenkinsfile using
@Library pinned to an explicit version — never an unpinned/floating
default unless the team has explicitly decided every repo should always
track main:
@Library('[email protected]') _
standardPipeline(
agentLabel: 'linux-x64',
serviceName: 'checkout-api',
buildCommand: 'npm ci && npm run build',
testCommand: 'npm test',
deployBranch: 'main',
deployTarget: 'staging'
)
This is the entire Jenkinsfile for a consuming repo — all pipeline logic lives in the library, and repo-specific values are passed as a config map.
Version the library deliberately. Tag releases (git tag v1.5.0)
and document a changelog; treat vars/ function signatures as a public
API — adding an optional Map key is backward compatible, removing or
renaming one is a breaking change that requires a major version bump and
a migration note for consumers.
Give the shared library its own CI (ironically, often a
Jenkinsfile in the library repo itself, or a separate lightweight
Groovy test runner) using the JenkinsPipelineUnit test framework so
vars/ and src/ logic is validated before a tag is cut — see
jenkins-groovy-scripting-best-practices
for the test setup.
Roll out breaking changes gradually. Cut a new major version tag,
update one or two pilot consumer repos to @Library('[email protected]'),
validate, then bulk-update the rest (a small script that finds and
updates the @Library line across consumer repos, submitted as
individual PRs — never force-push or bulk-edit consumer repos' default
branches without their own review).
vars/*.groovy thin (orchestration: stages, calling into src/)
and put real logic/business rules in src/ classes, which are easier to
unit test and reuse across multiple vars/ entry points..txt companion file next to each vars/*.groovy (e.g.
standardPipeline.txt) documenting the config map's expected keys — this
renders in the Jenkins "Global Variables Reference" and saves consumers
from reading the Groovy source to know what parameters exist.config.timeoutMinutes ?: 30) so a minimal consumer Jenkinsfile still works, and document required
keys explicitly (fail fast with a clear error if a required key like
serviceName is missing).Symptom: A shared library change breaks every consumer pipeline
simultaneously the moment it's merged to main.
Fix: Consumers should pin @Library('[email protected]') to an
explicit tag, not @Library('shared-lib') implicit-default or @main —
a tagged version isolates consumers from in-progress library changes
until they explicitly bump the pin.
Symptom: Adding a new required parameter to standardPipeline(...)
causes dozens of consumer Jenkinsfiles to fail with a null-pointer-style
Groovy error on their next build.
Fix: Make new parameters optional with a sensible default
(config.newThing ?: 'default') for a minor version; reserve breaking,
required-parameter changes for a major version bump with an explicit
migration announcement and grace period.
Symptom: NotSerializableException thrown from a src/ class used
inside a pipeline step.
Fix: Classes used inside Pipeline's CPS execution (anything invoked
from vars/ in the pipeline's execution context, e.g. objects held
across a stage) must implement Serializable; keep such classes free
of non-serializable fields (open file handles, threads) or mark them
transient.
Symptom: A vars/*.groovy function works when tested by one team but
throws "Scripts not permitted to use ..." for another team's pipeline.
Fix: This is the Groovy sandbox blocking a method/class not on the
approved list — see
jenkins-groovy-scripting-best-practices
for the script-approval workflow; don't work around it by disabling the
sandbox globally.
Symptom: A repo owner wants to delete an old shared-library
credential or an old library version, unaware three other teams'
Jenkinsfiles still pin that exact version/credential ID.
Fix: Before deleting a Jenkins credential or an old library tag,
search consumer Jenkinsfiles (grep -r "@Library('shared-lib@v1" . across
known consumer repos, or check the credential's "Used by" list if the
Credentials plugin exposes it) for references — deleting a
still-referenced credential or tag breaks every pipeline pinned to it
with no warning until the next build.
Scenario: An organization has 30 Node.js service repos, each with a near-identical Jenkinsfile. They centralize into a shared library so each repo's Jenkinsfile becomes ~10 lines, and a future change (e.g. adding a dependency-scan stage) needs only one PR in the library repo plus a version bump per consumer.
Library repo layout (jenkins-shared-library):
vars/nodeServicePipeline.groovy
vars/nodeServicePipeline.txt
src/org/example/pipeline/Notifier.groovy
vars/nodeServicePipeline.groovy:
def call(Map config = [:]) {
if (!config.serviceName) {
error "nodeServicePipeline: 'serviceName' is required"
}
pipeline {
agent { docker { image config.nodeImage ?: 'node:20.11-bullseye' } }
options { timeout(time: 20, unit: 'MINUTES') }
stages {
stage('Install & Test') {
steps {
sh 'npm ci'
sh 'npm test'
}
}
stage('Deploy') {
when { branch 'main' }
steps {
sh "make deploy SERVICE=${config.serviceName} TARGET=staging"
}
}
}
post {
failure {
script { org.example.pipeline.Notifier.notifyFailure(this, config.serviceName) }
}
}
}
}
Consuming repo's Jenkinsfile (identical pattern across all 30 repos, only
serviceName differs):
@Library('[email protected]') _
nodeServicePipeline(serviceName: 'checkout-api')
Adding a dependency-scan stage later means one PR to
vars/nodeServicePipeline.groovy, tagging v1.3.0, and each consumer repo
bumping @Library('[email protected]') → @Library('[email protected]')
on its own schedule instead of 30 separate Jenkinsfile edits.
Serializable requirements, and unit-testing vars//src/ code.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub selvarajmurugesan90/ops-engineering-skills --plugin cicd-tooling-skills13 skills in this plugin
/aws-codepipeline-and-codedeployDesigns AWS CodePipeline stage/action structure and integrates it with CodeDeploy deployment groups and appspec.yml for EC2/on-prem, ECS, or Lambda deploys. Use when the user asks to "set up CodePipeline," "add a CodeDeploy deployment group," "write an appspec.yml," "wire CodePipeline to CodeDeploy," "troubleshoot a stuck/failed CodePipeline action," or "add a manual approval action before an AWS deploy."
/azure-pipelines-yaml-and-multi-stageDesigns Azure Pipelines YAML (azure-pipelines.yml), multi-stage pipelines with environments/approvals, templates for reuse across repos, and self-hosted vs. Microsoft-hosted agent pools. Use when the user asks to "set up Azure Pipelines," "write an azure-pipelines.yml," "add a multi-stage pipeline with approvals," "create a reusable pipeline template," "configure a self-hosted agent pool," or "troubleshoot a stuck/failed Azure DevOps pipeline run."
/bamboo-pipeline-yaml-and-java-specsAuthors Atlassian Bamboo pipeline definitions using either Bamboo Specs (Java DSL, compiled and run to create/update a plan) or Bamboo's YAML specs format, covering plan/job/stage structure and how a Specs definition links to and updates a live Bamboo plan. Use when the user asks to "write a Bamboo Specs plan," "convert our Bamboo plan to code," "add a stage/job to a Bamboo build," "use Bamboo YAML specs," or "troubleshoot a Bamboo Specs plan not updating the linked plan."
/complete-cicd-pipeline-deployment-for-kubernetes-from-scratchBuilds a complete CI/CD pipeline for a Kubernetes-targeted service from an empty repo — source checkout, container image build, SCA/SAST security gates, registry push, and a deploy step that ends at a GitOps handoff (committing a new image tag to a manifests repo) rather than a direct kubectl apply or helm upgrade against the cluster. Use when the user asks to "build a full CI/CD pipeline for Kubernetes from scratch," "set up CI/CD that ends in a GitOps commit, not a cluster deploy," "wire a container build pipeline into Argo CD/Flux," or "go from an empty repo to a Kubernetes service deployed via GitOps end-to-end."
/complete-cicd-pipeline-deployment-for-serverless-from-scratchBuilds a complete CI/CD pipeline for a serverless (AWS Lambda-style) function from an empty repo — source checkout, zip/layer packaging (not a container image), SCA/SAST security gates, package upload, and a SAM/Serverless-Framework/CDK-style deploy step with alias-based canary traffic shifting, distinct from Kubernetes rollout mechanics. Use when the user asks to "build a full CI/CD pipeline for a Lambda function from scratch," "set up serverless CI/CD with canary traffic shifting," "wire SAM/Serverless Framework deploys into a pipeline," or "go from an empty repo to a function deployed with an alias-based canary."
/complete-cicd-pipeline-for-vm-based-workloads-from-scratchBuilds a complete CI/CD pipeline for a VM-based workload from an empty repo — source checkout, build, immutable machine-image baking (Packer-style AMI, not a container image or a zip), SCA/SAST security gates, and a deploy step that's either a blue-green instance-group swap or a config-management push (Ansible) to existing long-lived VMs, distinct from both container and serverless deploy mechanics. Use when the user asks to "build a full CI/CD pipeline for EC2/VM workloads from scratch," "bake an AMI in CI and roll it out blue-green," "push Ansible-managed config to existing VMs from a pipeline," or "go from an empty repo to a VM fleet deployed with a golden image and Auto Scaling Group swap."
Other plugins' skills for the same job