In one of my plugins I am using the GitSCM instance of a job to analyze the associated Git repository. This works for a lot of cases (input: a Jenkins run):
- For FreeStyle jobs I get the instance from AbstractProject.getSCM()
- For Pipelines jobs I get the instance from the job ((SCMTriggerItem) job).getSCMs()
- For Pipelines jobs with CpsScmFlowDefinition I get the instance from the definition ((CpsScmFlowDefinition) definition).getScm()
But when I use the following pipeline code in an integration test to check out a specific SHA-1 of a repository, then none of these options work to get the SCM. Is in such a case no SCM instance stored in the run or job?
(I get called with a GitSCM instance in a CheckoutListener, thus the instance actually is created)
checkout([$class: 'GitSCM', branches: [[name: '28af63def44286729e3b19b03464d100fd1d0587' ]], userRemoteConfigs: [[url: '" + REPOSITORY_URL + "']]])"
In the run I can find BuildData, GitTagAction and ScmRevisionState instances, but no one seems to link to the GitSCM.