Level 2 — Pipelines for teams · wrap-up
Cheat sheet & self-check
Every command from this section on one page.
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_NAME | PR 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) |
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>.groovy | Global steps/variables, one file per step, with a call() method |
src/com/acme/ci/Versioning.groovy | Classes for more complex logic |
resources/ | Non-Groovy files: pod templates, scripts, config |
test/ | Unit tests (JenkinsPipelineUnit) |
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 -w | Watch 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 jnlp | Agent connection logs |