Jenkins — Level by Level›Level 2 · Cheat sheet & self-check

Level 2 — Pipelines for teams · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

04 · Multibranch pipelines and webhooks

Conditions in a multibranch Jenkinsfile

when { changeRequest() }Only for pull-request builds
when { branch 'main' }Only for main
when { buildingTag() }Only when building a tag
when { tag pattern: 'v\\d+\\.\\d+\\.\\d+', comparator: 'REGEXP' }Only for semantic-version tags
env.CHANGE_ID / env.CHANGE_TARGET / env.BRANCH_NAMEPR number, PR target branch, branch name

Webhooks

https://jenkins.example.com/github-webhook/GitHub webhook endpoint (GitHub plugin)
https://jenkins.example.com/multibranch-webhook-trigger/invoke?token=<token>Generic trigger for other Git servers (Multibranch Scan Webhook Trigger plugin)

05 · Shared libraries

Using a library

@Library('platform-lib@v2.3.0') _Load a specific library version (top of the Jenkinsfile)
standardServicePipeline(app: 'orders-api')Call a whole pipeline defined in vars/standardServicePipeline.groovy
buildImage(name: 'orders-api')Call a step defined in vars/buildImage.groovy
def cfg = libraryResource 'templates/buildkit-pod.yaml'Load a file from resources/

Library layout

vars/<name>.groovyGlobal steps/variables, one file per step, with a call() method
src/com/acme/ci/Versioning.groovyClasses for more complex logic
resources/Non-Groovy files: pod templates, scripts, config
test/Unit tests (JenkinsPipelineUnit)

06 · Agents on Kubernetes

In the Jenkinsfile

agent { kubernetes { yaml '''...pod spec...''' } }Define the agent pod inline
agent { kubernetes { yamlFile 'ci/pod.yaml' } }Pod spec from a file in the repo
agent { kubernetes { inheritFrom 'python-311' } }Use a pod template defined centrally
container('node') { sh 'npm ci' }Run steps in a specific container of the pod

Troubleshoot

kubectl -n jenkins-agents get pods -wWatch agent pods being created and removed
kubectl -n jenkins-agents describe pod <agent-pod>Why it's Pending or failing (resources, image pull)
kubectl -n jenkins-agents logs <agent-pod> -c jnlpAgent connection logs