8

We have a private Atlassian Bitbucket Server (previously known as Stash) hosting our git repos.

How can I search across

  • all source files
  • in all branches
  • in all repos

I really want to avoid the process of checking out all repos locally, doing git pull and then recursive grep.

Some plugins were available in Atlassian Stash for "enterprise search" but they didn't work for us.

If you have gotten this to work, kindly share the steps to set it up :) :)

V-R
  • 1,309
  • 16
  • 32
vikingsteve
  • 38,481
  • 23
  • 112
  • 156
  • There's a paid plugin on the marketplace right now that adds Search functionality to Stash (Bitbucket). https://marketplace.atlassian.com/plugins/com.mohamicorp.stash.search-for-stash/server/overview – James Riche Feb 29 '16 at 01:36

3 Answers3

5

We also needed to implement a search for all our Stash projects. Looking into various options, the best implementation was to install a dedicated OpenGrok server.
The server's crontab runs a script every 10 minutes for doing the following:

  1. Get list of all project using Stash API
  2. For each project, get all repositories (using the API again)
  3. For each repository, clone or pull if exists
    • If you need every branch, find all branches and clone for each branch
  4. Once all sources are ready, run the OpenGrok indexing

It works very well for us, and was simple to implement.
I think that eventually, this should be done with a built-in add-on, but at the time, there was none to be found.

I hope this helps.

Eldad Assis
  • 10,464
  • 11
  • 52
  • 78
  • 1
    Right. I really wanted to avoid the "pull every repo" thing. What other options did you consider? – vikingsteve Oct 28 '15 at 09:17
  • 1
    Pulling every repo is very fast if it's already cloned. We also do it in parallel, so it's super fast. Other options where mainly finding a built in add-on (none was found) and implementing our own search. – Eldad Assis Oct 28 '15 at 15:17
  • What about this one, did you try it? https://marketplace.atlassian.com/plugins/com.mohamicorp.stash.search-for-stash – vikingsteve Oct 28 '15 at 19:13
  • No. We didn't try it, but you can try it for free and share your experience here. – Eldad Assis Oct 29 '15 at 06:40
3

Disclosure: I'm a Bitbucket (Stash) Product Manager

As others have suggested, this isn't something that's available in-product currently. The good news is that we're working on code search at the moment. The bad news for your question is that for performance reasons (and because it's a relatively uncommon use case from our research) we are only planning to index the tip of the default branch (usually master).

If you could describe what you're trying to achieve in more detail I'd be happy to look into alternatives.

One option would be to script up a series of "git grep" commands across the repos on the server (assuming you have access). You do this at your own risk though, any direct operations run against repos on the server aren't supported.

Rog
  • 4,075
  • 2
  • 24
  • 35
  • 1
    Hi Rog and thanks for outing yourself as a knowledgeable insider ;) Really what we want to do is quite simple, look for uses of a particular class or constant or dependency or import across all our repos (some 70+). If we can only do that on default branch (`develop`) then that's not the end of the world, although all branches (or a pattern, like `develop|master|release/*` would be nice. Do you have an ETA on this "enterprise search" feature? And we are on Stash 3.5, my colleague suggested upgrading to bitbucket yesterday - are the two very different (or is it a marketing name change)? – vikingsteve Oct 29 '15 at 07:53
  • We don't have a timeline we can share at this stage. Upgrading to Bitbucket is recommended. Apart from API changes that come with a major version bump, the underlying product hasn't changed dramatically, so it should be familiar, with some new features we've added along the way. – Rog Oct 30 '15 at 22:26
  • @rog do you have updates on this issue or ticket inside Atlassian to track the progress? – Rafael Gorski Jan 20 '16 at 14:13
  • @Rog do you have updates ? – David Mar 31 '22 at 17:19
  • I'm no longer working on the product, but per other answers code search has been available for some years now. – Rog Apr 01 '22 at 22:33
3

According to an Atlassian ticket to track this, code search is built-in functionality in Bitbucket Server 4.6 (aka Stash). See the release notes.

Jon Onstott
  • 13,499
  • 16
  • 80
  • 133