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

Created on 6 May 2015  Â·  12Comments  Â·  Source: GitTools/GitVersion

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.

Most helpful comment

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.

All 12 comments

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

https://github.com/libgit2/libgit2sharp/pull/852

You can find some more information about this here:

https://github.com/ParticularLabs/GitVersion/issues/38

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

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

:+1:

Hm. Loooking further into this, we are using the git checkout hack as proposed in this issue https://github.com/ParticularLabs/GitVersion/issues/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 https://github.com/ParticularLabs/GitVersion/issues/431
Next release?

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

https://github.com/ParticularLabs/GitVersion/pull/432

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

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?

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
https://github.com/ParticularLabs/GitVersion/issues/436#issuecomment-100129697
.

http://www.ndcoslo.com/

@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. :smiley:

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

Agreed! :+1:

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

packages\GitVersion.CommandLine.3.6.2\tools\GitVersion.exe /updateassemblyinfo SharedAssemblyInfo.cs [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.

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.

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

Was this page helpful?
0 / 5 - 0 ratings