huserben / TfsExtensions

Extensions for TFS 2015+ such as custom Widgets (require TFS 2017) and Build Tasks
MIT License
45 stars 22 forks source link

Trigger Build out of a release build does not resolve BUILD_REPOSITORY_URI #1

Closed lukx closed 7 years ago

lukx commented 7 years ago

Hey In our Visual Studio Team Services build chain, we have chosen the Trigger Build-Buildstep to run our integration tests after a successful release, because we appreciated the straightforwardness of its configuration. We are running it as the last step of our Release configuration. However, the variable BUILD_REPOSITORY_URI does not get resolved, and we are out of ideas as to why that might be. Full log is adjacent, but I suspect the rest to be follow-up errors. Could you tell us what we're doing wrong, please? Thanks

2017-03-28T14:03:30.4694745Z Executing the powershell script: C:\a\_tasks\TriggerBuild_xxxxxxxxxxxxxxxxxxxx\1.3.15\triggerbuild.ps1
2017-03-28T14:03:31.3353482Z Using Current Team Project URL
2017-03-28T14:03:31.3403975Z ##[error]System.Management.Automation.ItemNotFoundException: Cannot find path 'BUILD_REPOSITORY_URI' because it does not exist.
2017-03-28T14:03:31.3403975Z    at System.Management.Automation.SessionStateInternal.GetChildItems(String path, Boolean recurse, UInt32 depth, CmdletProviderContext context)
2017-03-28T14:03:31.3403975Z    at Microsoft.PowerShell.Commands.GetChildItemCommand.ProcessRecord()
2017-03-28T14:03:31.3403975Z Path to Server: /xxxxxxx
2017-03-28T14:03:31.3403975Z Using Default Credentials
2017-03-28T14:03:31.3403975Z Build In Queue Condition is enabled
2017-03-28T14:03:31.3403975Z Current Build Definition shall be included
2017-03-28T14:03:31.3403975Z Add Deploy Azure App Service to list of blocking Build Definitions
2017-03-28T14:03:31.3403975Z Dependant Build Condition is enabled
2017-03-28T14:03:31.3403975Z Add Deploy Azure App Service to list of dependent build definitions
2017-03-28T14:03:31.3403975Z Checking if blocking builds are queued
2017-03-28T14:03:31.3403975Z Checking Build Definition: Provider Service Build
2017-03-28T14:03:31.6905319Z ##[error]System.UriFormatException: Invalid URI: The hostname could not be parsed.
2017-03-28T14:03:31.6905319Z    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
2017-03-28T14:03:31.6905319Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.CheckProtocol(Uri uri)
2017-03-28T14:03:31.6905319Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetRequest(Uri uri)
2017-03-28T14:03:31.6905319Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2017-03-28T14:03:31.6905319Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2017-03-28T14:03:31.7197813Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array.
2017-03-28T14:03:31.7197813Z    at CallSite.Target(Closure , CallSite , Object , Int32 )
2017-03-28T14:03:31.7197813Z    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
2017-03-28T14:03:31.7197813Z    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
2017-03-28T14:03:31.7197813Z    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-03-28T14:03:31.7911635Z ##[error]System.UriFormatException: Invalid URI: The hostname could not be parsed.
2017-03-28T14:03:31.7911635Z    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
2017-03-28T14:03:31.7911635Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.CheckProtocol(Uri uri)
2017-03-28T14:03:31.7911635Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetRequest(Uri uri)
2017-03-28T14:03:31.7911635Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2017-03-28T14:03:31.7911635Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2017-03-28T14:03:31.7941635Z Checking Build Definition: Deploy Azure App Service
2017-03-28T14:03:31.7951639Z ##[error]System.UriFormatException: Invalid URI: The hostname could not be parsed.
2017-03-28T14:03:31.7951639Z    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
2017-03-28T14:03:31.7951639Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.CheckProtocol(Uri uri)
2017-03-28T14:03:31.7951639Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetRequest(Uri uri)
2017-03-28T14:03:31.7961637Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2017-03-28T14:03:31.7961637Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2017-03-28T14:03:31.7961637Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array.
2017-03-28T14:03:31.7961637Z    at CallSite.Target(Closure , CallSite , Object , Int32 )
2017-03-28T14:03:31.7961637Z    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
2017-03-28T14:03:31.7961637Z    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-03-28T14:03:31.7961637Z ##[error]System.UriFormatException: Invalid URI: The hostname could not be parsed.
2017-03-28T14:03:31.7961637Z    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
2017-03-28T14:03:31.7961637Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.CheckProtocol(Uri uri)
2017-03-28T14:03:31.7961637Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetRequest(Uri uri)
2017-03-28T14:03:31.7971642Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2017-03-28T14:03:31.7971642Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2017-03-28T14:03:31.7971642Z None of the blocking builds is queued - proceeding
2017-03-28T14:03:31.7971642Z Checking if dependant build definitions last builds were successful
2017-03-28T14:03:31.7981636Z Checking Build Definition Deploy Azure App Service
2017-03-28T14:03:31.7991639Z ##[error]System.UriFormatException: Invalid URI: The hostname could not be parsed.
2017-03-28T14:03:31.7991639Z    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
2017-03-28T14:03:31.7991639Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.CheckProtocol(Uri uri)
2017-03-28T14:03:31.7991639Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetRequest(Uri uri)
2017-03-28T14:03:31.7991639Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2017-03-28T14:03:31.7991639Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2017-03-28T14:03:31.7991639Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array.
2017-03-28T14:03:31.7991639Z    at CallSite.Target(Closure , CallSite , Object , Int32 )
2017-03-28T14:03:31.7991639Z    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
2017-03-28T14:03:31.7991639Z    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-03-28T14:03:31.8001638Z ##[error]System.UriFormatException: Invalid URI: The hostname could not be parsed.
2017-03-28T14:03:31.8001638Z    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
2017-03-28T14:03:31.8001638Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.CheckProtocol(Uri uri)
2017-03-28T14:03:31.8001638Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetRequest(Uri uri)
2017-03-28T14:03:31.8001638Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2017-03-28T14:03:31.8001638Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2017-03-28T14:03:31.8001638Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array.
2017-03-28T14:03:31.8001638Z    at CallSite.Target(Closure , CallSite , Object , Int32 )
2017-03-28T14:03:31.8001638Z    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
2017-03-28T14:03:31.8001638Z    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
2017-03-28T14:03:31.8001638Z    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-03-28T14:03:31.8011640Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array.
2017-03-28T14:03:31.8011640Z    at CallSite.Target(Closure , CallSite , Object , Int32 )
2017-03-28T14:03:31.8011640Z    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
2017-03-28T14:03:31.8011640Z    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
2017-03-28T14:03:31.8011640Z    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-03-28T14:03:31.8011640Z Last build of definition Deploy Azure App Service was not successful (state is: ) - will not trigger new build
2017-03-28T14:03:31.8396800Z ##[error]PowerShell script completed with 12 errors.
huserben commented 7 years ago

Hi

what configuration are you running the Task on? (On Prem, Online, what TFS version). I tested these things with Visual Studio Team Services.

If you use the "Current Team Project" it will try to fetch the URL via this environment variable as described here (https://www.visualstudio.com/en-us/docs/build/define/variables see BUILD_REPOSITORY_URI). As I understand it those variables should automatically be set on your build agent...

You could try to use the "Custom Team Project" and specifiy the url yourselve and see if that works as a first workaround.

Please let me know if this works, otherwise I can try to look deeper into it.

Thanks for your feedback :-)

lukx commented 7 years ago

We are using Online VSTS along with a hosted agent, so whatever Microsoft gives us... I think I see the difference - we have configured the Build step as a part of our release build, where the predefined variables differ (https://www.visualstudio.com/en-us/docs/build/concepts/definitions/release/variables)

We tried to configure it into a build step in VSTS. There, $($tfsServer) resolves as https://our-account.visualstudio.com/our-project/_git/our-repo/our-project

so "our-project" (which I chose as a pseudonym) is there twice, yielding a 404 (and adjacent errors). I am suspecting, https://github.com/huserben/TfsExtensions/blob/master/BuildTasks/triggerbuildtask/triggerbuild.ps1#L28 might be unsuitable for VSTS setups, in addition to using the variable that's only available during a Build.

$(System.TeamFoundationCollectionUri) is available in both contexts, maybe that's helpful?

I'll try to find out whether I can somehow help develop the PS1-Script in our VSTS environment

huserben commented 7 years ago

Hi

I wasn't aware that the variables differ depending on the configuration, but then it makes sense. I will have a look at it as soon as I can, but that will probably not happen before the weekend...

Feel free to check out the code and make adjustements yourselve if you feel like it.

Did you as well try specifying the url by hand as part of the "Basic Configuration"?

lukx commented 7 years ago

Thanks, yes we did try that - looks like $(System.TeamFoundationCollectionUri)$(System.TeamProject) is the correct path at our environment. I could reproduce the API calls from the script manually, too. Now we get a JSON Parse error, that "." is not a valid json primitive, but that's beyond this ticket, I believe.

huserben commented 7 years ago

Hi

ok, I will try to change that as soon as possible. For the further issues you could maybe send the same request on your local machine, e.g. via a tool like Postman (https://www.getpostman.com/) to the exact same url + with the same authorization and check the return value yourselve. I assume something is wrong either with the URL or the credentials, which will cause the request to be redirected and you will get back HTML rather than the JSON we expect.

huserben commented 7 years ago

Hi

I made the change so that the script uses System.TeamFoundationCollectionUri now. The Task was updated and is uploaded to the Marektplace.

Could you please quickly check if it now works and let me know?

Thanks!

nobitagamer commented 7 years ago

The Uri work as expected, you can close this issue now.