Skip to content

Docs for building PRs with VSTS #993

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
JakeGinnivan opened this issue Aug 10, 2016 · 19 comments
Closed

Docs for building PRs with VSTS #993

JakeGinnivan opened this issue Aug 10, 2016 · 19 comments
Labels

Comments

@JakeGinnivan
Copy link
Contributor

VSTS seems to specify a refspec when fetching, something like this:

git -c http.extraheader="AUTHORIZATION: bearer ********" fetch --tags --prune --progress origin +refs/pull/31/merge:refs/remotes/pull/31/merge

This means it doesn't fetch master or develop.

The workaround is:

  1. Add a git fetch task in
    image
    The argument should be -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" fetch --prune --progress origin
  2. Turn on allow scripts to access OAuth token.
    image

We need to add this info to the docs.

@pascalberger
Copy link
Member

I'm not sure this is always the best way to to go. There is also another issue that tags were not fetched in certain scenarios, for which there is already another workaround documented here, by setting the build clean variable. Also calling git directly depends which version of the agent is in use, the old agent used LibGit, with the new one it should be possible to call git directly.

IMHO it would be a better approach to document what is required for GitVersion to work properly (eg. have all tags fetched, have certain branches fetched, etc), and list the possible ways to achieve this with their pros/cons, so that the user can decide what best fits its setup.

@JakeGinnivan
Copy link
Contributor Author

I don't know how to make pull requests fetch everything without this change? I am using on prem agents

@pascalberger
Copy link
Member

pascalberger commented Aug 10, 2016

@JakeGinnivan Ah yes, you're right. Seems to always checkout a ref.<

But instead of having the user to add an additional task to every build definition, wouldn't it be better if the GitVersion VSTS task or GitVersion itself would fetch the missing branches itself?

@JakeGinnivan
Copy link
Contributor Author

This can probably be built into GitVersion itself to fetch automatically, and throw if the OAuth token is not available

@roryprimrose
Copy link

This would presumably be surfaced as an option on the GitVersion build step.

@JakeGinnivan
Copy link
Contributor Author

It would be built into the core. Disabled with the /nofetch option.

@JakeGinnivan
Copy link
Contributor Author

Your using on-premises build agents?

@roryprimrose
Copy link

Both actually. The one I'm currently troubleshooting is a hosted agent with the repository that just has some binaries and a nuspec.

Is there a recommended option for current versions that will sort out this PR issue and the possibility of tags not being fetched?

@JakeGinnivan
Copy link
Contributor Author

Follow the instructions in the first post to work around it. I haven't had time to really take this further as this workaround worked for me

@roryprimrose
Copy link

First post being the extra build step outlined above? Seems like a good time to look at that new meta-task thingy :)

@JakeGinnivan
Copy link
Contributor Author

heh, I don't want to make the workaround the primary fix. Id prefer we just build it in and make it transparent :)

@JakeGinnivan
Copy link
Contributor Author

@nulltoken do you know if we can specify additional headers through libgit2sharp?

Need to do something like this git -c http.extraheader="AUTHORIZATION: bearer <authtoken>" fetch --tags --prune --progress origin +refs/head/*:refs/remotes/origin/*

@nulltoken
Copy link
Contributor

@JakeGinnivan Not that I know of.

@ethomson @carlosmn Did you make something like this happen?

@ethomson
Copy link

ethomson commented Sep 6, 2016

@nulltoken No, we do not yet support this, though it seems like it would be a nice addition. Patches welcome! ;)

@nulltoken
Copy link
Contributor

@ethomson Thanks for the feedback ❤️

@jessehouwing
Copy link

When built into the task itself, it will be able to access the oauth token without needing a special setting.

@pascalberger
Copy link
Member

Since libgit2sharp doesn't seem to support passing an OAuth token, it may be the best solution at the moment to implement this in the VSTS task, and require the user to make the OAuth token available to the task and have Git installed on the agent (which should be no longer an issue using the new agent).

@jessehouwing
Copy link

The task itself is able to access the OAuth token directly using the following code (old powershell host, the code for powershell3 is very similar, but it looks like you're still on the old host):

$VSTSEndpoint = Get-ServiceEndpoint -Context $distributedTaskContext -Name "SystemVssConnection"
if ($VSTSEndpoint -eq $null)
{
    throw "Could not locate Service Endpoint SystemVssConnection."
}
$baererToken = $VSTSEndpoint.Authorization.Parameters.AccessToken

I'd personally stick a demand for git.exe on the task and have checkbox to perform git fetch origin --tags as part of the task execution.

You could skip the demand and perform a find-command to see if you can find git.exe from the session, or just package mingw as part of the task itself like Visual Studio 15 is doing since the latest preview C:\Program Files (x86)\Microsoft Visual Studio\VS15Preview\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git should have everything you need to package Git as part of your task..

@stale
Copy link

stale bot commented Jun 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 29, 2019
@stale stale bot closed this as completed Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants