Skip to content

LibGit2Sharp.LibGit2SharpException: Request failed with status code: 401 / Unsupported URL protocol #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
babadofar opened this issue May 6, 2015 · 12 comments

Comments

@babadofar
Copy link

Hi,
I'm trying to use GitVersionTask, 3.0.0-beta2 with TeamCity 8.0.5
Have set the environment variables GITVERSION_REMOTE_PASSWORD and GITVERSION_REMOTE_USERNAME as explained here: https://github.com/ParticularLabs/GitVersion/wiki/MSBuild-Task-Usage

We normally use ssh to checkout from bitbucket, but I tried using https as well, they give slightly different error messages, both seem to indicate connection/authentication failures.

ssh error message:
[UpdateAssemblyInfo] WriteVersionInfoToBuildLog
[16:57:50][WriteVersionInfoToBuildLog] Applicable build agent found: 'TeamCity'.
[16:57:50][WriteVersionInfoToBuildLog] Executing PerformPreProcessingSteps for 'TeamCity'.
[16:57:50][WriteVersionInfoToBuildLog] One remote found (origin -> '[email protected]').
[16:57:50][WriteVersionInfoToBuildLog] Fetching from remote 'origin' using the following refspecs: +refs/heads/:refs/remotes/origin/.
[16:57:50]
[WriteVersionInfoToBuildLog] Error occurred: LibGit2Sharp.LibGit2SharpException: Unsupported URL protocol
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in :line 0
at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteSafeHandle remote, Signature signature, String logMessage) in :line 0

https error message:
[...csproj] UpdateAssemblyInfo
[16:44:00][UpdateAssemblyInfo] WriteVersionInfoToBuildLog
[16:44:00][WriteVersionInfoToBuildLog] Applicable build agent found: 'TeamCity'.
[16:44:00][WriteVersionInfoToBuildLog] Executing PerformPreProcessingSteps for 'TeamCity'.
[16:44:00][WriteVersionInfoToBuildLog] One remote found (origin -> 'https://....git').
[16:44:00][WriteVersionInfoToBuildLog] Fetching from remote 'origin' using the following refspecs: +refs/heads/:refs/remotes/origin/.
[16:44:01]
[WriteVersionInfoToBuildLog] Error occurred: LibGit2Sharp.LibGit2SharpException: Request failed with status code: 401
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in :line 0
at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteSafeHandle remote, Signature signature, String logMessage) in :line 0
at LibGit2Sharp.Network.DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, Signature signature, String logMessage) in :line 0
at LibGit2Sharp.Network.Fetch(Remote remote, FetchOptions options, Signature signature, String logMessage) in :line 0
at GitVersion.GitHelper.NormalizeGitDirectory(String gitDirectory, Authentication authentication, Boolean noFetch) in c:\BuildAgent\work\5106452ed7682238\GitVersionCore\BuildServers\GitHelper.cs:line 23
at GitVersion.TeamCity.PerformPreProcessingSteps(String gitDirectory, Boolean noFetch) in c:\BuildAgent\work\5106452ed7682238\GitVersionCore\BuildServers\TeamCity.cs:line 26
at VersionAndBranchFinder.TryGetVersion(String directory, Tuple`2& versionAndBranch, Config configuration, Boolean noFetch) in c:\BuildAgent\work\5106452ed7682238\GitVersionTask\VersionAndBranchFinder.cs:line 31
at GitVersionTask.WriteVersionInfoToBuildLog.InnerExecute() in c:\BuildAgent\work\5106452ed7682238\GitVersionTask\WriteVersionInfoToBuildLog.cs:line 58
at GitVersionTask.WriteVersionInfoToBuildLog.Execute() in c:\BuildAgent\work\5106452ed7682238\GitVersionTask\WriteVersionInfoToBuildLog.cs:line 34
[16:44:01][....csproj failed.

@gep13
Copy link
Member

gep13 commented May 7, 2015

To the best of my knowledge, SSH is currently not supported in libgit2, therefore not supported in GitVersion.

libgit2/libgit2sharp#852

You can find some more information about this here:

#38

Therefore, you best option would be to use HTTPS connection. Perhaps open another issue specifically for that?

@babadofar
Copy link
Author

Thanks, it definitely helped when I stopped using ssh.
Got it working now!

@gep13
Copy link
Member

gep13 commented May 7, 2015

👍

@babadofar
Copy link
Author

Hm. Loooking further into this, we are using the git checkout hack as proposed in this issue #21 So there should be no need for gitVersionTask to checkout branches, they are already there.
What we really need seems to be the nofetch option, as described here #431
Next release?

@gep13
Copy link
Member

gep13 commented May 7, 2015

Yip, this has been merged, and should be in the next release:

#432

If you want to, you can compile from source and give it a try if you wanted to try this out.

@asbjornu
Copy link
Member

asbjornu commented May 8, 2015

Our build configuration using GitVersionTask in TeamCity looks like this:

  • General Settings
    • Build number format: %system.GitVersion.FullSemVer%
  • Version Control Settings
    • VCS checkout mode: Automatically on agent
  • VCS Root
    • Fetch URL: https://[email protected]/repository.git
    • Authentication method: Password
    • Username: user
    • Password: *****
  • Parameters
    • system.GitVersion.FullSemVer: ''
    • env.GITVERSION_REMOTE_USERNAME: user
    • env.GITVERSION_REMOTE_PASSWORD: *****

I believe this is everything required to get all git operations to work with GitVersion. Does your build configuration look identical to this, @babadofar?

@babadofar
Copy link
Author

Thanks Asbjørn!
Very nice overview of the settings needed for TeamCity
I did manage to get it working, using https as method to connect to
bitbucket. The problem is, our entire system is set up to use ssh.
Of course, the right thing to do here is to start porting projects. Then we
could finally get rid of the infamous "checkout all branches" powershell
hack :)

2015-05-08 9:14 GMT+02:00 Asbjørn Ulsberg [email protected]:

Our build configuration using GitVersionTask in TeamCity looks like this:

  • General Settings
    • Build number format: %system.GitVersion.FullSemVer%
      • Version Control Settings
    • VCS checkout mode: Automatically on agent
      • VCS Root
    • Fetch URL: https://[email protected]/repository.git
    • Authentication method: Password
    • Username: user
    • Password: *****
      • Parameters
    • system.GitVersion.FullSemVer: ''
    • env.GITVERSION_REMOTE_USERNAME: user
    • env.GITVERSION_REMOTE_PASSWORD: *****

I believe this is everything required to get all git operations to work
with GitVersion. Does your build configuration look identical to this,
@babadofar https://github.com/babadofar?


Reply to this email directly or view it on GitHub
#436 (comment)
.

http://www.ndcoslo.com/

@asbjornu
Copy link
Member

asbjornu commented May 8, 2015

@babadofar, even better would be for libgit2 to get SSH support, since SSH is unquestionably preferable when it is available. But until then, HTTPS is a compromise we're willing to accept since the value GitVersion gives us far outweighs HTTPS' downsides. 😃

@gep13
Copy link
Member

gep13 commented May 8, 2015

@asbjornu said...
even better would be for libgit2 to get SSH support,

Agreed! 👍

@chris1248
Copy link

chris1248 commented Mar 1, 2017

We are having this problem in our TeamCity setup. I am accessing the repo using SSH, and I get a very similar callstack:

[11:56:23]INFO [03/01/17 11:56:23:30] Working directory: C:\apps\TeamCity\BuildAgent\work\185ab46dd115b347
[11:56:23]INFO [03/01/17 11:56:23:30] IsDynamicGitRepository: False
[11:56:23]INFO [03/01/17 11:56:23:33] Returning Project Root from DotGitDirectory: C:\apps\TeamCity\BuildAgent\work\185ab46dd115b347\.git - C:\apps\TeamCity\BuildAgent\work\185ab46dd115b347
[11:56:23]INFO [03/01/17 11:56:23:33] Running on Windows.
[11:56:23]INFO [03/01/17 11:56:23:33] Applicable build agent found: 'TeamCity'.
[11:56:23]WARN [03/01/17 11:56:23:34] TeamCity doesn't make the current branch available through environmental variables.
[11:56:23]
[11:56:23]Depending on your authentication and transport setup of your git VCS root things may work. In that case, ignore this warning.
[11:56:23]
[11:56:23]In your TeamCity build configuration, add a parameter called `env.Git_Branch` with value %teamcity.build.vcs.branch.<vcsid>%
[11:56:23]
[11:56:23]See http://gitversion.readthedocs.org/en/latest/build-server-support/build-server/teamcity for more info
[11:56:23]INFO [03/01/17 11:56:23:34] Branch from build environment: 
[11:56:23]ERROR [03/01/17 11:56:23:45] An unexpected error occurred:
[11:56:23]LibGit2Sharp.LibGit2SharpException: Unsupported URL protocol
[11:56:23]   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in c:\Git\LibGit2Sharp\LibGit2Sharp\Core\Ensure.cs:line 154
[11:56:23]   at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteHandle remote, IEnumerable`1 refSpecs, GitFetchOptions fetchOptions, String logMessage) in c:\Git\LibGit2Sharp\LibGit2Sharp\Core\Proxy.cs:line 2168
[11:56:23]   at LibGit2Sharp.Commands.Fetch(Repository repository, String remote, IEnumerable`1 refspecs, FetchOptions options, String logMessage) in c:\Git\LibGit2Sharp\LibGit2Sharp\Commands\Fetch.cs:line 74
[11:56:23]   at GitTools.Git.GitRepositoryHelper.NormalizeGitDirectory(String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch)
[11:56:23]   at GitVersion.GitPreparer.Initialise(Boolean normaliseGitDirectory, String currentBranch)
[11:56:23]   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig)
[11:56:23]   at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
[11:56:23]   at GitVersion.Program.VerifyArgumentsAndRun()

Our TeamCity setup is:
Fetch URL: ssh://git@*****:xxxxx/foo/bar.git
Authentication Method: Uploaded Key
Uploaded Key: *****
I have zero environment or configuration variables set.

@chris1248
Copy link

chris1248 commented Mar 1, 2017

Huh: I did this:

add a parameter called env.Git_Branch with value %teamcity.build.vcs.branch.<vcsid>%

and the problem went away. Cool! No idea why it didn't throw a better exception, but this will work for now.

@pdubb29
Copy link

pdubb29 commented Dec 22, 2020

The one thing that fixed it for me today based on having was putting in %teamcity.build.branch% with the same environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants