sentry-netlify-build-plugin icon indicating copy to clipboard operation
sentry-netlify-build-plugin copied to clipboard

Gitlab - SentryCLI failed to set commits

Open djw27 opened this issue 5 years ago • 23 comments

When using this plugin with a Gitlab integration, we run in to the following error:

12:51:09 PM:   cmd: '/opt/buildhome/.netlify-build-plugins/node_modules/@sentry/cli/sentry-cli releases set-commits ac28e1c49ac9312242e09696c2046c53c3926835 --commit theworkshop/web-app@ac28e1c49ac9312242e09696c2046c53c3926835'
12:51:09 PM: }
12:51:09 PM: ​
12:51:09 PM: ┌──────────────────────────────────────────────┐
12:51:09 PM: │ Plugin "@sentry/netlify-build-plugin" failed │
12:51:09 PM: └──────────────────────────────────────────────┘
12:51:09 PM: ​
12:51:09 PM:   Error message
12:51:09 PM:   Error: SentryCLI failed to set commits. You likely need to set up a repository or repository integration.
12:51:09 PM:            Read more: https://docs.sentry.io/workflow/releases/?platform=python#install-repo-integration

When running the command locally to replicate the issue, we get a bit more information around why this is failing:

$ sentry-cli releases set-commits ac28e1c49ac9312242e09696c2046c53c3926835 --commit theworkshop/web-app@ac28e1c49ac9312242e09696c2046c53c3926835

error: Unknown repo 'theworkshop/web-app'

The error we're running into seems to be due to how whitespace is handled in the repository name with the Gitlab integration

Modifying the command locally to the following fixes the issue:

$ sentry-cli releases set-commits ac28e1c49ac9312242e09696c2046c53c3926835 --commit theworkshop\ /\ web-app@ac28e1c49ac9312242e09696c2046c53c3926835

It should also probably be documented somewhere that the what Sentry uses as 'name' is actually configurable on Gitlab - i.e. if a user has modified their repo name with Gitlab, then this script won't work as this script actually uses the repo 'slug' rather than name for matching.

djw27 avatar Aug 10 '20 13:08 djw27

Just to add a comment on a potential 'fix' until I have chance to look at this in any more detail.

https://github.com/getsentry/sentry-netlify-build-plugin/blob/master/index.js#L110 could be edited to the following, you'd probably want a bit more of a definitive check however:

const repositoryParts = process.env.REPOSITORY_URL.split(/[:/]/).slice(-2)

const repository = process.env.REPOSITORY_URL.includes('gitlab') ? repositoryParts.join(' / ') : repositoryParts.join('/')

I assume other people using Gitlab are experiencing this issue - it would be good to have more evidence of this though!

djw27 avatar Sep 09 '20 10:09 djw27

Yes I can confirm I'm having the same issue too. It would be nice to see it addressed.

CongeeCafe avatar Oct 03 '20 19:10 CongeeCafe

I'm having the same issue, though using a Github repository.

cpannwitz avatar Oct 06 '20 06:10 cpannwitz

Same issue with a private github repo.

TylerAHolden avatar Oct 07 '20 01:10 TylerAHolden

Same issue with a private Github repo. The weird thing is that it works correctly for the first time today (which I implemented), but then it doesn't work anymore. I didn't make any even a change in the implementation.

Sly777 avatar Oct 07 '20 11:10 Sly777

Same issue with a private github repo. Worked for the first commit and the stopped working due to the 'SentryCLI failed to set commits.' error.

tysonmatanich avatar Oct 18 '20 23:10 tysonmatanich

I was able to get it working, however the article by @jonesphillip needs updated to state that private repos need to enable GitHub integrations.

Settings > Integrations > GitHub > Add Installation

After the integration was installed I then had to add the specific repo under the installed GitHub integrations under the 'Configurations' tab using the 'Add Repository' dropdown button.

tysonmatanich avatar Oct 19 '20 01:10 tysonmatanich

I had the same issue, this is how I solved it :

Settings > my-org > Integrations > GitHub

Then make sure your private repository is listed in the configuration. Then re-build on Netlify.

(Thanks @tysonmatanich for pointing me in the right direction.)

marcpicaud avatar Nov 10 '20 18:11 marcpicaud

I have the same issue with Gitlab. It worked on the first run, but fails on subsequent runs with an "unknown repo" error. The Sentry UI recognizes the repo with no issue and the release that did work shows commits.

@djw27 What did you end up doing?

freshbreweddesign avatar Dec 17 '20 17:12 freshbreweddesign

I have the same issue with Gitlab. It worked on the first run, but fails on subsequent runs with an "unknown repo" error. The Sentry UI recognizes the repo with no issue and the release that did work shows commits.

@djw27 What did you end up doing?

@dunsworth we've left this as an unresolved issue on the back-burner - hopefully we'll get around coming up with a solution in the new year

djw27 avatar Dec 18 '20 10:12 djw27

@djw27 Any update on this issue. I am facing same issue with Gilab integration. If it is not fixed any possible workaround will be much appreciated. Thanks

devs4522 avatar Jan 07 '21 14:01 devs4522

@djw27 Any update on this issue. I am facing same issue with Gilab integration. If it is not fixed any possible workaround will be much appreciated. Thanks

@devs4522 no update yet I'm afraid - will post here when we get around to it

djw27 avatar Jan 12 '21 15:01 djw27

I have the same issue with a github private repo. Worked on first try but fails on subsequent runs. What's odd is that the Configure github tab shows non of the repos I authorized via the dropdown. I've tried this multiple times and when I try to Add Installation the sentry github app is already authorized yet its not reflected on the sentry UI.

Here's where it's erroring out.

9:28:55 AM: Error: Command failed: /opt/build/repo/.netlify/plugins/node_modules/@sentry/cli/sentry-cli releases set-commits b02f83cafc02ecba9f6583f29b5c9beab3b70b7a --commit xxx/yyy@b02f83cafc02ecba9f6583f29b5c9beab3b70b7a 9:28:55 AM: error: Unknown repo 'xxx/yyy'

I've obfuscated the repo url, but the issue is that the plugin should be attempting to commit to @xxx/yyy instead of xxx/yyy as it is a private repo.

Any pointers would be useful. Thanks

P.S - Also worth nothing that my Sentry org id is say xxx instead of @xxx. (Not sure if this has anything to do with the repo url)

juanpprieto avatar Jan 20 '21 17:01 juanpprieto

I think I might be having the same problem

jasikpark avatar Mar 09 '21 02:03 jasikpark

Is it dependent on having your github integrated with sentry first??

jasikpark avatar Mar 09 '21 02:03 jasikpark

@jasikpark Yes you'll want to make sure you have your GitHub integration installed and the relevant repository added. You can find more information about that here: https://docs.sentry.io/product/releases/setup/release-automation/

Let me know if you're still having problems after that

jonesphillip avatar Mar 09 '21 04:03 jonesphillip

@juanpprieto did you add your add your repository as well? You'll need to do that as an additional step after installing the integration. More information on that here: https://docs.sentry.io/product/releases/setup/release-automation/

jonesphillip avatar Mar 09 '21 04:03 jonesphillip

That worked for me -- I thought I had already authorized it since I had a whole fun problem where I initially made an email authed account, and then installed the Github App on my Github account, which sent me to an account creation page with no "login instead" link, so I created another account with the same email.

This then meant that my original account was getting 401 errors when trying to load my projects page in the site, and I first just tried to use the new Github authed account, but I found out that I was setup with a legacy subscription due to signing up via the Github App, meaning I couldn't use newer features like the Performance section.

I then deleted that account, but that did not remove the GIthub App from my profile, which meant that when I saw a section claiming I needed Github auth, I thought I was good. Then I found https://help.sentry.io/product-features/integrations/github-why-can-t-i-add-a-repository/ and followed its recommendation, and my problems were solved at that point.

I still haven't actually received any error reports, even though I manually caused them, for example by calling foobar() in the terminal, but that's another story.

jasikpark avatar Mar 09 '21 04:03 jasikpark

Even though SENTRY_REPOSITORY variable is set on Netlify its still not used when deploying

VitalijusZimaitis avatar Feb 15 '22 18:02 VitalijusZimaitis

@VitalijusZimaitis that is because the version wasn't updated in Netlify plugins yet. See my comment here: https://github.com/getsentry/sentry-netlify-build-plugin/pull/46#issuecomment-1038620658

alias-mac avatar Feb 17 '22 05:02 alias-mac

For anyone still having this issue

  1. Go to Settings > Repositories
  2. Copy the name on the top (if your repo is gitlab.com/xxx/yyy then Sentry will show like Xxx / Yyy).
  3. Go to Netlify > Build > Environment
  4. Create SENTRY_REPOSITORY and set this value you copied

Enjoy ✨

kasvith avatar May 16 '22 17:05 kasvith

Life saver @kasvith! Spent way too long on this – perhaps the readme should be updated to indicate the name needs to exactly match the text string displayed in the Sentry UI and is not actually the repository slug.

saikojosh avatar Aug 05 '22 15:08 saikojosh

i have the same issue on private gitlab repo

muh-hizbe avatar Jan 07 '23 07:01 muh-hizbe