[workflow] Git step to check out a commit instead of a branch

2,250 views
Skip to first unread message

Lóránt Pintér

unread,
Mar 25, 2015, 2:26:37 PM3/25/15
to jenkins...@googlegroups.com
Hi,

Is it possible to check out a particular commit hash, instead of a branch with the git workflow step?

Thanks,
Lorant

Baptiste Mathus

unread,
Mar 28, 2015, 7:28:20 AM3/28/15
to jenkins...@googlegroups.com
Just a wild guess: since in Git branch names are actually not very special things, which in the end get translated to the associated sha1, did you just try to put branch: 'abc123' e.g. ?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c99f109f-8d16-44a4-b480-d6d3de2c6f7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !

Lóránt Pintér

unread,
Mar 29, 2015, 3:35:19 PM3/29/15
to jenkins...@googlegroups.com, jenkins...@googlegroups.com
I tried, but it results in weird errors about no commit being found to build:

Running: Git
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url g...@github.com:prezi/boxfish-text-editor.git # timeout=10
Fetching upstream changes from g...@github.com:prezi/boxfish-text-editor.git
 > git --version # timeout=10
 > git -c core.askpass=true fetch --tags --progress g...@github.com:prezi/boxfish-text-editor.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/2.0^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/2.0^{commit} # timeout=10
 > git rev-parse origin/2.0^{commit} # timeout=10
Running: Allocate workspace : Body : End
Running: Allocate workspace : End
Running: Allocate node : Body : End
Running: Allocate node : End
Running: Mail
Running: Print Message
Error in boxfish-text-editor: Author: Unknown Author <boxfi...@prezi.com>

hudson.AbortException: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:918)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1017)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:106)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:70)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution.start(AbstractSynchronousStepExecution.java:34)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:136)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:100)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
at Script1.run(Script1.groovy:14)
at Unknown.Unknown(Unknown)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:69)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:100)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:76)
at sun.reflect.GeneratedMethodAccessor147.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.dispatch(CollectionLiteralBlock.java:55)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.item(CollectionLiteralBlock.java:45)
at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:33)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:22)
at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
at com.cloudbees.groovy.cps.Next.step(Next.java:58)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:145)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:268)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:71)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:177)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:175)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:111)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)


Lóránt


You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/M3tDkHYFfWo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS6X58xzLEy23-iaxMU%2Bny7Z0mO%3D16_3sar_z_2exk2gsw%40mail.gmail.com.

Jesse Glick

unread,
Jun 16, 2015, 6:50:37 PM6/16/15
to jenkins...@googlegroups.com
On Wednesday, March 25, 2015 at 10:26:37 AM UTC-4, Lóránt Pintér wrote:
Is it possible to check out a particular commit hash, instead of a branch with the git workflow step?

No, but it should be possible with some exotic options to GitSCM, run via the generic checkout step. 

Stephan Stachurski

unread,
Jun 17, 2015, 6:53:25 PM6/17/15
to jenkins...@googlegroups.com
I would really like to figure this out. Haven't transitioned to workflow yet, but using our conventional jenkins pipeline, we have been burned in the past when the head of a branch changed between the start and end of the pipeline.

Jesse Glick

unread,
Aug 12, 2015, 8:50:44 PM8/12/15
to Jenkins Users
On Wednesday, June 17, 2015 at 2:53:25 PM UTC-4, Stephan Stachurski wrote:
using our conventional jenkins pipeline, we have been burned in the past when the head of a branch changed between the start and end of the pipeline.

If using a multibranch workflow (currently in beta), you just say `checkout scm` to get a consistent commit anywhere within the build. 

Simone Vratogna

unread,
Mar 17, 2016, 3:51:31 PM3/17/16
to Jenkins Users
Hello, I'm interested as well. Did you find any solution?

Baptiste Mathus

unread,
Mar 18, 2016, 7:58:46 AM3/18/16
to jenkins...@googlegroups.com

Did you try using the generic SCM way as proposed by Jesse?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Simone Vratogna

unread,
Mar 18, 2016, 8:11:19 AM3/18/16
to jenkins...@googlegroups.com
I did, but to me it doesn't work, it checks out anyway the next branch... :(

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/M3tDkHYFfWo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS5GJLNw5k_G1D1dsRhwgz17msLfJP08tadFfnkGdDV1iQ%40mail.gmail.com.

Björn Pedersen

unread,
Mar 18, 2016, 9:12:42 AM3/18/16
to Jenkins Users
Hi,

you could install gerrit-trigger-plugin (you do not need to use gerrit for your use-case) and use the gerrit-trigger checkout strategy that can
use  hashes/tags/etc...

Björn

Baptiste Mathus

unread,
Mar 18, 2016, 9:50:00 AM3/18/16
to jenkins...@googlegroups.com
Now thinking about it, another solution is to just use the plain git CLI. (Requires git on the path, note)

def theSha = "...."
sh "git checkout $theSha"

// here you go

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Simone Vratogna

unread,
Mar 21, 2016, 3:07:35 PM3/21/16
to jenkins...@googlegroups.com
Yes, but there is a problem. In the build information I think it will display the sha1 of the branch checked out automatically rather than that of the specific commit that I checkout by hand (at least this is what I though I have seen while I was testing a similar approach ;) ).
But thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/M3tDkHYFfWo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS4HMFa9anD6WHygSURsRZZNWU_RfwC3cj24chvOQJYYuA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages