Obtain GitSCM from a checkout step in pipeline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Obtain GitSCM from a checkout step in pipeline

Ulli Hafner
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.





--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/F3C48AB7-3CD8-430F-9FBF-D82784BA6C7A%40gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Obtain GitSCM from a checkout step in pipeline

Jesse Glick-4
You could possibly reconstruct this information from `ArgumentsAction`. Probably more reliable to use `CheckoutListener` though.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr3JEWZLK7%3DO9wYd12F%3D9_7jOQahL4VCPSitzFGvzCry8Q%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Obtain GitSCM from a checkout step in pipeline

Jesse Glick-4
Or directly check `WorkflowRun.getSCMs()`. Not currently exposed as an API via `Run` (`getChangeSets()` is a bit different).

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0VRnkGQDGxa%2ByeQxbBpwwji6KsnG_0M7FBFL1-%3Drww3w%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Obtain GitSCM from a checkout step in pipeline

Ulli Hafner

Or directly check `WorkflowRun.getSCMs()`. Not currently exposed as an API via `Run` (`getChangeSets()` is a bit different).


Yes that works, thanks!


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/F74BA7C9-6273-4E65-8ED6-875461901FD1%40gmail.com.