Multibranch pipeline - source code present but .git file missing

346 views
Skip to first unread message

Sharan Basappa

unread,
Feb 10, 2017, 11:02:44 PM2/10/17
to Jenkins Users
I am using multi-branch pipeline and I find that source code is present under {workspace}@script directory but .git files are missing in any of the directories.
So, when I try to stash so that I can move to another branch, I get error saying that, "it does not appear to be a git repository"

Let me know what the issue is?

The following are some additional information:
1) I am using Jenkinsfile that is at the root of my git repository
2) I have created a Jenkins job using multi-branch pipeline and have only given path to git and only option to pool SCM every minute
3) I am not checking out any repository explicitly in my Jenkinsfile - I still find source code in the workspace through

Daniel Beck

unread,
Feb 11, 2017, 4:46:23 AM2/11/17
to jenkins...@googlegroups.com

> On 11.02.2017, at 05:02, Sharan Basappa <sharan....@gmail.com> wrote:
>
> 3) I am not checking out any repository explicitly in my Jenkinsfile - I still find source code in the workspace through

That's probably the reason, and the reason it's in a wrong directory. Don't try to be clever here. `checkout scm`.

Sharan Basappa

unread,
Feb 11, 2017, 9:08:14 AM2/11/17
to Jenkins Users, m...@beckweb.net
Daniel,

Don't try to be clever here. `checkout scm`.

You are giving me more credit than I deserve.

I really don't understand how source files from Git can appear in the workspace and .git dir is missing.
In fact, for all the source files corresponding to every branch, there is no .git dir.
I have seen this issue only when I started using multibranch pipeline and not with pipeline or other build job types.
Also, in this case alone, I am using Jenkinsfile driven build steps

Mark Waite

unread,
Feb 11, 2017, 10:47:10 PM2/11/17
to Jenkins Users, m...@beckweb.net
Sharan,

Daniel was trying to tell you that you're misunderstanding what is a workspace and what isn't a workspace.

The place where you're finding the Jenkinsfile is a temporary holding location that exists for the purpose of reading the Jenkinsfile.  It is not a workspace.  It is not a place where you should expect to find the rest of your code.  At the moment, that temporary holding location happens to also include other files, but that is more an accident of the nature of git than it is a capability on which you can rely.

In order to use your source code in a Jenkins pipeline, you need to checkout that source code in one of the early stages of your pipeline.  The examples you've shared don't seem to include a "checkout scm" step, so you have no sources to use.

For examples of the syntax of "checkout scm", you can use the "Pipeline Syntax" hyperlink on the left of pipeline job pages.

Mark Waite

--
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/eebf0cb3-d3ec-4298-bef9-8ed3baa87bb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sharan Basappa

unread,
Feb 12, 2017, 11:14:44 AM2/12/17
to Jenkins Users, m...@beckweb.net
Thank you, Daniel and Mark. Unfortunately, none of these things are documented. At least that I know of.
That's when I actually put sh "ls" in the pipeline script to list. When I found my files, I assumed everything is taken care by Jenkins.

Coming to checkout - how can I make out that I checkout the correct branch. As everything is happening automatically. I cannot predict what branch name
an user would check-in with. I see that Jenkins itself is checking out the branch that has changed.

Regards,
Sharan

Mark Waite

unread,
Feb 12, 2017, 11:39:27 AM2/12/17
to Jenkins Users, m...@beckweb.net
Refer to https://github.com/jenkinsci/pipeline-examples/tree/master/jenkinsfile-examples for several samples which perform a checkout.  Checkout will default to checkout the same branch from which the Jenkinsfile was read.

Refer to https://jenkins.io/doc/book/pipeline/getting-started/#defining-a-pipeline-in-scm and https://jenkins.io/doc/book/pipeline/jenkinsfile/ for more information on Jenkinsfile.  Particularly, refer to the paragraph which says:

From within node, the first order of business will be to checkout the source code for this project.

If there are areas of that book where you learn something new and would be willing to share with others, you can fork a copy of that site through https://github.com/jenkins-infra/jenkins.io/tree/master/content/doc/book and submit your information as a pull request.  If you find errors or improvements, I'm sure others will be very grateful if you share what you've learned as a pull request to the book.

Mark Waite

Reply all
Reply to author
Forward
0 new messages