Source Code Management, Webhooks, and Triggers
What this domain covers
Questions test whether a repository change actually reaches a build. You need Git plugin behaviours, the webhook endpoint per provider, and cron semantics for polling and scheduled triggers.
Core rules
- Pipeline checkout.
checkout scmreuses the pipeline job's SCM configuration; the explicit form isgit url: 'git@host:org/repo.git', branch: 'main', credentialsId: 'gh-deploy'. - Git plugin behaviours (Additional Behaviours in freestyle): shallow clone with depth N, sparse checkout, advanced submodule configuration, clean before checkout, checkout to a subdirectory, polling ignores commits in certain paths, and wipe-out-repository-and-force-clone.
- Webhook endpoints. GitHub plugin/branch source:
https://<jenkins>/github-webhook/. GitLab:/project/or the build-token URL. Bitbucket:/bitbucket-hook/. Generic Webhook Trigger:/generic-webhook-trigger/invoke?token=…. The endpoint only exists once the plugin is installed. - Two things must hold for a GitHub push to build: the repository webhook points at the endpoint, and the job has "GitHub hook trigger for GITScm polling" ticked. A multibranch project instead needs branch-source triggers ("Scan by webhook"), and a webhook there starts indexing, not a build.
- Cron syntax has five fields - MINUTE HOUR DAY-OF-MONTH MONTH DAY-OF-WEEK.
His a hash placeholder that spreads load;H/5 * * * *is not the same as*/5 * * * *. Shortcuts include@hourly,@daily,@midnight,@weekly. - Trigger types:
pollSCM('H/15 * * * *')inspects the repository;cron('H 3 * * *')builds on a clock;upstream(upstreamProjects: 'a', threshold: hudson.model.Result.SUCCESS)chains jobs; token-authorized remote trigger URLs let external systems start builds. - "Suppress automatic SCM triggering" stops the GitHub hook starting a build when a different CI already built that commit.
Worked example
Pushes to a multibranch project build nothing, yet polling works and the webhook returns 200. Reasoning: a 200 proves the endpoint and secret are fine, so the hook fired but nothing was configured to react. The project has no branch-source scan trigger, so enable "Scan by webhook" (with period-based "Scan Multibranch Pipeline Triggers" as a fallback) and confirm the scan creates or updates the branch job. Polling worked because the periodic scan, not the hook, was doing the work.
Traps
Confusing pollSCM (looks at the repository) with cron (looks at the clock); writing a four-field cron; using */5 where H/5 was intended and hammering the SCM server; embedding credentials in the remote URL; assuming a webhook builds pull requests without a change-request branch source.