Declarative Pipeline with agent any already runs 'Declarative: Checkout SCM'
automatically before user stages the explicit stage('Checkout') was cloning
the repo a second time for no reason. Remove it entirely; capture GIT_COMMIT_SHA
and GIT_PREV_SHA at the top of stage('Detect') using the already-present workspace.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
credentials() in the pipeline-level environment{} block causes an immediate
abort before any stage runs if the credential ID does not exist in Jenkins.
The node is released, post{} runs without a node context, and sh steps fail
with 'Required context class hudson.FilePath is missing'.
Fix: remove REGISTRY_CREDS and GITEA_CREDS from environment{}, replace with
withCredentials() inside the stages that actually need them (Build & Push,
Publish). Wrap post{cleanup} sh calls in try/catch as a safety net.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>