Checking out a Git project does something strange
Asked by Bjorn Harvold:

Hi,

I am trying to integrate Sentry CLI into my CI/CD workflow.

Once everything builds, I send artifacts to Sentry. Sentry will look at the Git log to see what changed since last release.

The problem is, Sentry complains because it cannot match the remote Git repo. When i run git remote -v inside the plan folder, it shows me a local file directory instead of my remote hosted repo on Bitbucket.

So Sentry complains with:

    DEBUG   2019-03-15 16:52:01.492404779 +07:00   not a match: file:///media/user/external/bamboo/xml-data/build-dir/_git-repositories-cache/debbfac5447105f03d2e672cc6b40afd775f0a46 != https://bitbucket.org/uberdevelopment/uber-spa


Answers:
author: Daniel Santos
body: Hi [@Bjorn Harvold](/t5/user/viewprofilepage/user-id/712360)

This is indeed expected behavior.

Bamboo does use cache repositories for better scalability. Multiple plans can use the same repository, therefore, saving network bandwidth. There are other reasons for this that I would not be the better person to explain.

In the repository advanced configuration, you will see that we can disable caching on remote agents, but this will still not solve your issue. The Bamboo server will still have the cache.

There are some articles written to provide alternatives for users trying to commit and push during a build. You will be able to see in those articles that the remote URL is manually configured:

* [How to commit and push to a Git repo during a build](https://confluence.atlassian.com/bamkb/how-to-commit-and-push-to-a-git-repo-during-a-build-720641378.html)
* [How to push to repository under SSH protocol using Script task](https://confluence.atlassian.com/bamkb/how-to-push-to-repository-under-ssh-protocol-using-script-task-747831642.html)

What I suggest as a workaround for you is manually configuring the remote repository as performed on those articles.

comments: author: Bjorn Harvold
body: Hi Daniel,

Thank you for your feedback.

Specifically for my purposes, you are suggesting that I add a remote like so:

    git remote add central https://username:${bamboo_bitbucket_password}@bitbucket.org/path/to/reponame.git

Sentry is failing when it tries to verify that the repo is indeed the repo at origin. Will adding another remote fix that?

Cheers


author: Daniel Santos
body: I don't really know Sentry, what I know is that Sentry seems to expect the local repository to be pointing to the main repository directly. If this is the case, setting the remote should fix the issue or at least move you forward.

Let's give it a try and check what happens.


author: Bjorn Harvold
body: Hi Daniel,

I added a remote as I wrote above. It shows up as central, above origin, when I do a "git remote -v".

central https://\<hidden\>:\<hidden\>@bitbucket.org/uberdevelopment/uber-spa (fetch)  
central https://\<hidden\>:\<hidden\>@bitbucket.org/uberdevelopment/uber-spa (push)  
origin file:///media/user/external/bamboo/xml-data/build-dir/_git-repositories-cache/c0db605baf9e80f875cbed09008f36a37fe6f6f2 (fetch)  
origin file:///media/user/external/bamboo/xml-data/build-dir/_git-repositories-cache/c0db605baf9e80f875cbed09008f36a37fe6f6f2 (push)

But it is not being picked up by Sentry. Sentry logs are still only comparing origin entry.


author: Daniel Santos
body: Hi [@Bjorn Harvold](/t5/user/viewprofilepage/user-id/712360)

Like I shared before, I'm not sure how Sentry works. I just shared a suggestion to set the remote repository configuration once I know that Bamboo uses a shared repository.

I think that you should try seeking for Sentry direct support. This seems to be their channel <https://sentry.io/contact/support/>.


author: Bjorn Harvold
body: Hi Daniel,

I do believe this is a Bamboo issue if it does something to the Git remote repository to not point at the original remote origin. It's not expected Git behavior and not a use case I think Sentry could anticipate.

What happens if I set remote origin back to its original Bitbucket location? Will Bamboo barf?

Thanks


author: Daniel Santos
body: Hi [@Bjorn Harvold](/t5/user/viewprofilepage/user-id/712360)

I shared two links with you. In the first one, the solution comes from setting a central repository. In the second one, it comes from setting a new origin.
> What happens if I set remote origin back to its original Bitbucket location? Will Bamboo barf?

I don't think that is a big deal, it should work in my opinion. I just share a warning that it might affect the new commit/push tasks added in latest versions of Bamboo.  

Do you want to try this and share here what you get?


author: Bjorn Harvold
body: Hi Daniel,

Thank you for the feedback. So I set the origin to Bitbucket then tried to run a build. The build immediately succeeded and nothing happened. I tried adding the local Git repo, that Bamboo creates, as central but still nothing. My current setup is like this:

central file:///media/user/external/bamboo/xml-data/build-dir/_git-repositories-cache/c0db605baf9e80f875cbed09008f36a37fe6f6f2 (fetch)  
central file:///media/user/external/bamboo/xml-data/build-dir/_git-repositories-cache/c0db605baf9e80f875cbed09008f36a37fe6f6f2 (push)  
origin https://\<username\>:\<password\>@bitbucket.org/uberdevelopment/uber-spa (fetch)  
origin https://\<username\>:\<password\>@bitbucket.org/uberdevelopment/uber-spa (push)

Am I missing something?

Thoughts?


author: Daniel Santos
body: Hi [@Bjorn Harvold](/t5/user/viewprofilepage/user-id/712360)

Have you tried leaving only the **origin** configured?  
I don't know how Sentry works and extra entries might be confusing it.

Maybe it worths a try.


author: Bjorn Harvold
body: Hi Daniel,

The job never gets that far. Bamboo stops working a few seconds after I start it whether I have only origin or origin and central remotes configured. Thinking it doesn't like that the local cached version of the repo isn't origin.

Thoughts?


author: Daniel Santos
body: I think you are right, the checkout task may be expecting something different from the git repository configuration.
> Thoughts?

Yes, please try to check the option **Force Clean Build** in your source code checkout task or add the task **Clean working directory**at the beginning of your job. That should work around this problem.


author: Bjorn Harvold
body: Hi Daniel,

When I Force Clean Build, Bamboo removes the git remote I manually added through the console and resets Git back to how Bamboo likes it.

Sentry works if I set git origin while the job is building. Pretty hacky but I could run a script that sets git remote origin every time.

Any better suggestions?


author: Daniel Santos
body: Hi [@Bjorn Harvold](/t5/user/viewprofilepage/user-id/712360)

That is the way I see it could work, still using the Bamboo checkout task. Yes, you will need to change the origin of every build.

Other option would be cloning the repository manually using a script task and taking control of the whole process involving the git repository.

Please keep in mind that the checkout task is supposed to provide you with the repository source code, and that is the way Bamboo does to make it scalable. There is no right and wrong on how to clone a source, but if you think this should be done differently, please create a feature request in our issue system <https://jira.atlassian.com/issues/> and share your reasons there. Our developers will be happy to have your feedback.  


author: Bjorn Harvold
body: Hi Daniel,

Yes that's what I did. Working :-) Thank you for your patience and help.

Cheers!