huserben / TfsExtensions

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

Error "Failed to find api location for area" when triggering build on TFS 2017 Update 1 #91

Closed jawn closed 5 years ago

jawn commented 5 years ago

I get the error

Failed to find api location for area

when using the trigger build task from a release definition. OAuth is enabled.

The build to trigger is in the same team collection and project, so I am using OAuth with empty token. I get the same error message whether Customer Team Project Url is enabled or not.

Version info

Log

2018-08-20T14:33:58.2975432Z ##[section]Starting: Trigger a new build of

2018-08-20T14:33:58.3399481Z ==============================================================================

2018-08-20T14:33:58.3400065Z Task : Trigger Build

2018-08-20T14:33:58.3400511Z Description : This tasks allows to trigger a new Build (add it to the queue) as part of a Build Definition. It contains as well some conditions that can be applied, for example if the last build of certain definition was successful or not.

2018-08-20T14:33:58.3400972Z Version : 3.0.1

2018-08-20T14:33:58.3401223Z Author : Benjamin Huser

2018-08-20T14:33:58.3401520Z Help :

2018-08-20T14:33:58.3401835Z ==============================================================================

2018-08-20T14:33:59.3885630Z Using Custom Team Project Url

2018-08-20T14:33:59.3891439Z Server URL: hidden serverurl

2018-08-20T14:33:59.3892537Z Team Project: hidden team project name

2018-08-20T14:33:59.3893273Z Trying to fetch authentication token from system...

2018-08-20T14:33:59.3916728Z Using OAuth Access Token

2018-08-20T14:33:59.4884599Z (node:1316) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to find api location for area: Location id: e81700f7-3be2-46de-8624-2eb35882fcaa

2018-08-20T14:33:59.5099253Z ##[section]Finishing: Trigger a new build of build name

huserben commented 5 years ago

It could be possible that the API used for retrieving the ID is not yet available in your version of TFS.

Could you try to query the following url (with Postman or your browser) and see whether you get back a project with the name you're looking for: https://<yourTfsUrl>:<port>/_apis/projects

If you are in a hurry you could as well try go for the latest 2. version which should work without a problem on TFS 2017. Functionality wise the difference to 3. is minimal. However if you could provide me with infos so I can make appropriate changes on the 3.* version I would vey much appreciate it.

huserben commented 5 years ago

Hi @jawn

just to check my assumption with the "too old API" I created a preview package that includes a change on how the Team Project Id is fetched. Now if you use the same team project as the original build it will not fetch the GUID over the API with the name, but just take the already existing GUID from an environment variable. That should get us around the issue, in case this API is the only not available...

benjhuser.tfs-extensions-build-tasks-3.1.0_preview.vsix.zip

Could you please have a try with the version provided and let me know whether it works or not?

jawn commented 5 years ago

Thanks for the quick follow up @huserben.

When I import this one I get the message 'The task.json file was not found in contribution triggerbuildtask. '

huserben commented 5 years ago

Sorry seems like I had a small issue in my script that created the "single version" package. This one should contain the correct structure:

benjhuser.tfs-extensions-build-tasks-3.1.0_preview.vsix.zip

Really sorry for that Trial and Error we have to do, but at the moment I really don't have any opportunity to test it in a similar environment myself.

jawn commented 5 years ago

No problem, I appreciate your rapid feedback.

I was able to install this 3.1.0 preview version on TFS 2017 Update 1

It seems the error still remains.

2018-08-22T07:10:10.4328561Z ##[section]Starting: Trigger a new build of *hidden*
2018-08-22T07:10:10.4795157Z ==============================================================================
2018-08-22T07:10:10.4795691Z Task         : Trigger Build
2018-08-22T07:10:10.4796230Z Description  : This tasks allows to trigger a new Build (add it to the queue) as part of a Build Definition. It contains as well some conditions that can be applied, for example if the last build of certain definition was successful or not.
2018-08-22T07:10:10.4796856Z Version      : 3.1.0
2018-08-22T07:10:10.4797182Z Author       : Benjamin Huser
2018-08-22T07:10:10.4797483Z Help         : 
2018-08-22T07:10:10.4797854Z ==============================================================================

2018-08-22T07:10:12.3856882Z (node:6156) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to find api location for area: Location id: e81700f7-3be2-46de-8624-2eb35882fcaa
2018-08-22T07:10:12.3955989Z Using current Collection Url
2018-08-22T07:10:12.3956477Z Using current Team Project
2018-08-22T07:10:12.3956941Z Team Project: *hidden* with ID 5b74265a-fcbe-4486-a6d9-c4badb376a06
2018-08-22T07:10:12.3957401Z Server URL: *hidden*
2018-08-22T07:10:12.3957805Z Trying to fetch authentication token from system...
2018-08-22T07:10:12.3958197Z Using OAuth Access Token
2018-08-22T07:10:12.3980131Z ##[section]Finishing: Trigger a new build of *hidden*
huserben commented 5 years ago

Hi

hmm strange, it seems it triggers a build anyway? Was it actually working apart from the error message printed out?

As well, could you once try to set the system.debug variable to true and post the output of the task? Maybe this helps determing the problem a bit better.

jawn commented 5 years ago

The build is still not triggered, I see no additional info after launching the triggering build with a debug flag. However, I am calling this task from a Release definition. Should I test it from a build directly instead?

huserben commented 5 years ago

Ok, it might be a good idea to try it out in the build to see whether the Release might create the problem. As well as you are using the OAuth token approach, did you make sure to allow the OAuth Token access for the phase where the task is in? This should be somewhere in the options of the Release Definition (if I remember correctly, as it changed somewhen in VSTS, so I'm not entirely sure how it was in TFS 2017).

grafik

jawn commented 5 years ago

Tested again with similar resutls:

Detailed logging:

******************************************************************************
Starting: Trigger a new build of **buildname**
******************************************************************************
==============================================================================
Task         : Trigger Build
Description  : This tasks allows to trigger a new Build (add it to the queue) as part of a Build Definition. It contains as well some conditions that can be applied, for example if the last build of certain definition was successful or not.
Version      : 3.1.0
Author       : Benjamin Huser
Help         : 
==============================================================================
agent.TempDirectory=c:\AgentDir\w\_temp
loading inputs and endpoints
loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
loading INPUT_AUTHENTICATIONMETHOD
loading INPUT_BLOCKINPROGRESSBUILDS
loading INPUT_BUILDDEFINITION
loading INPUT_CANCELBUILDSIFANYFAILS
loading INPUT_DEFINITIONISINCURRENTTEAMPROJECT
loading INPUT_DEFINITIONISINSAMECOLLECTION
loading INPUT_DELAYBETWEENBUILDS
loading INPUT_DEPENDENTONFAILEDBUILDCONDITION
loading INPUT_DEPENDENTONSUCCESSFULBUILDCONDITION
loading INPUT_DOWNLOADBUILDARTIFACTS
loading INPUT_DROPDIRECTORY
loading INPUT_ENABLEBUILDINQUEUECONDITION
loading INPUT_FAILTASKIFBUILDSNOTSUCCESSFUL
loading INPUT_FAILTASKIFCONDITIONSARENOTFULFILLED
loading INPUT_IGNORESSLCERTIFICATEERRORS
loading INPUT_INCLUDECURRENTBUILDDEFINITION
loading INPUT_QUEUEBUILDFORUSERTHATTRIGGEREDBUILD
loading INPUT_STOREINENVIRONMENTVARIABLE
loading INPUT_TREATPARTIALLYSUCCEEDEDBUILDASSUCCESSFUL
loading INPUT_USESAMEBRANCH
loading INPUT_USESAMESOURCEVERSION
loading INPUT_WAITFORQUEUEDBUILDSTOFINISH
loading INPUT_WAITFORQUEUEDBUILDSTOFINISHREFRESHTIME
loaded 26
Agent.ProxyUrl=undefined
Agent.CAInfo=undefined
Agent.ClientCert=undefined
Agent.SkipCertValidation=undefined
definitionIsInCurrentTeamProject=true
definitionIsInSameCollection=true
tfsServer=null
teamProject=null
buildDefinition=**buildname**
ignoreSslCertificateErrors=false
queueBuildForUserThatTriggeredBuild=true
useSameSourceVersion=false
useSameBranch=true
branchToUse=null
waitForQueuedBuildsToFinish=false
waitForQueuedBuildsToFinishRefreshTime=60
failTaskIfBuildsNotSuccessful=true
cancelBuildsIfAnyFails=false
treatPartiallySucceededBuildAsSuccessful=false
downloadBuildArtifacts=false
dropDirectory=c:\AgentDir\w
storeInEnvironmentVariable=false
demands=null
queueid=null
buildParameters=null
delayBetweenBuilds=0
authenticationMethod=OAuth Token
username=null
password=null
enableBuildInQueueCondition=false
includeCurrentBuildDefinition=true
blockingBuildsList=null
blockInProgressBuilds=false
dependentOnSuccessfulBuildCondition=false
dependentBuildsList=null
dependentOnFailedBuildCondition=false
dependentFailingBuildsList=null
failTaskIfConditionsAreNotFulfilled=false
Using current Collection Url
Using current Team Project
Team Project: ***
Server URL: ***
Trying to fetch authentication token from system...
Using OAuth Access Token
(node:5332) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to find api location for area: Location id: e81700f7-3be2-46de-8624-2eb35882fcaa
******************************************************************************
Finishing: Trigger a new build of **buildname**

I see the following event log entry:

image

image

Apart from updating to a newer TFS version (which is not an option at this point), is there any additional troubleshooting I can take, e.g. by monitoring the network, etc?

huserben commented 5 years ago

Hi

ok, I found the following issue on another github repo that seemed to have the same problem: https://github.com/Microsoft/vsts-cli/issues/149 (even the guids of the error seem to match...)

So maybe what you could try is to update the Build Agent to the newest (supported) version and maybe reconfigure it if it is not too much effort, to see whether this solves the problem...

Otherwise the message from the event log suggest that is has something todo with a trust level ("Registration was not found or is not medium trust"). Maybe there is some security setting with the webserver that is hosting TFS so the request gets rejected or something (Sorry I'm definetly no TFS/IIS Expert so I have to start guessing here...)

huserben commented 5 years ago

Will close due to inactivity - please reopen if needed.

icnocop commented 4 years ago

I am also experiencing this issue with v3.0.11 (single version) on TFS 2015 Update 4. Installing 3.1.0_preview doesn't produce the error message, but also doesn't trigger the new build.

Is 3.1.0_preview older than 3.0.11 in "releases"?

2020-01-21T22:24:00.3850255Z Starting task: Trigger a new build of Dev
2020-01-21T22:24:01.0100093Z ##[debug]agent.TempDirectory=undefined
2020-01-21T22:24:01.0100093Z ##[debug]agent.workFolder=c:\agent\_work
2020-01-21T22:24:01.0100093Z ##[debug]loading inputs and endpoints
2020-01-21T22:24:01.0100093Z ##[debug]loading ENDPOINT_AUTH_$/
2020-01-21T22:24:01.0100093Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_AUTHENTICATIONMETHOD
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_BLOCKINPROGRESSBUILDS
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_BUILDDEFINITION
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_BUILDPARAMETERS
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_CANCELBUILDSIFANYFAILS
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_DEFINITIONISINCURRENTTEAMPROJECT
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_DEFINITIONISINSAMECOLLECTION
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_DELAYBETWEENBUILDS
2020-01-21T22:24:01.0100093Z ##[debug]loading INPUT_DEPENDENTONFAILEDBUILDCONDITION
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_DEPENDENTONSUCCESSFULBUILDCONDITION
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_DOWNLOADBUILDARTIFACTS
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_DROPDIRECTORY
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_ENABLEBUILDINQUEUECONDITION
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_FAILTASKIFBUILDSNOTSUCCESSFUL
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_FAILTASKIFCONDITIONSARENOTFULFILLED
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_IGNORESSLCERTIFICATEERRORS
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_INCLUDECURRENTBUILDDEFINITION
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_QUEUEBUILDFORUSERTHATTRIGGEREDBUILD
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_STOREINENVIRONMENTVARIABLE
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_TREATPARTIALLYSUCCEEDEDBUILDASSUCCESSFUL
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_USESAMEBRANCH
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_USESAMESOURCEVERSION
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_WAITFORQUEUEDBUILDSTOFINISH
2020-01-21T22:24:01.0256480Z ##[debug]loading INPUT_WAITFORQUEUEDBUILDSTOFINISHREFRESHTIME
2020-01-21T22:24:01.0256480Z ##[debug]loaded 26
2020-01-21T22:24:01.0256480Z ##[debug]Agent.ProxyUrl=undefined
2020-01-21T22:24:01.0256480Z ##[debug]Agent.CAInfo=undefined
2020-01-21T22:24:01.0256480Z ##[debug]Agent.ClientCert=undefined
2020-01-21T22:24:01.0256480Z ##[debug]Agent.SkipCertValidation=undefined
2020-01-21T22:24:01.0256480Z ##[debug]definitionIsInCurrentTeamProject=true
2020-01-21T22:24:01.0256480Z ##[debug]definitionIsInSameCollection=true
2020-01-21T22:24:01.0256480Z ##[debug]tfsServer=null
2020-01-21T22:24:01.0256480Z ##[debug]teamProject=null
2020-01-21T22:24:01.0256480Z ##[debug]buildDefinition=Dev
2020-01-21T22:24:01.0256480Z ##[debug]ignoreSslCertificateErrors=false
2020-01-21T22:24:01.0256480Z ##[debug]queueBuildForUserThatTriggeredBuild=true
2020-01-21T22:24:01.0256480Z ##[debug]useSameSourceVersion=false
2020-01-21T22:24:01.0256480Z ##[debug]useSameBranch=true
2020-01-21T22:24:01.0256480Z ##[debug]branchToUse=null
2020-01-21T22:24:01.0256480Z ##[debug]waitForQueuedBuildsToFinish=false
2020-01-21T22:24:01.0256480Z ##[debug]waitForQueuedBuildsToFinishRefreshTime=60
2020-01-21T22:24:01.0256480Z ##[debug]failTaskIfBuildsNotSuccessful=true
2020-01-21T22:24:01.0256480Z ##[debug]cancelBuildsIfAnyFails=false
2020-01-21T22:24:01.0256480Z ##[debug]treatPartiallySucceededBuildAsSuccessful=false
2020-01-21T22:24:01.0256480Z ##[debug]downloadBuildArtifacts=false
2020-01-21T22:24:01.0256480Z ##[debug]dropDirectory=c:\agent\_work
2020-01-21T22:24:01.0256480Z ##[debug]storeInEnvironmentVariable=true
2020-01-21T22:24:01.0256480Z ##[debug]demands=null
2020-01-21T22:24:01.0256480Z ##[debug]queueid=null
2020-01-21T22:24:01.0256480Z ##[debug]buildParameters=BuildConfiguration: Release, RunTests: true, DeployBinaries: false, ContinueOnTestRunFailures: false
2020-01-21T22:24:01.0256480Z ##[debug]delayBetweenBuilds=0
2020-01-21T22:24:01.0256480Z ##[debug]authenticationMethod=OAuth Token
2020-01-21T22:24:01.0256480Z ##[debug]username=null
2020-01-21T22:24:01.0256480Z ##[debug]password=null
2020-01-21T22:24:01.0256480Z ##[debug]enableBuildInQueueCondition=false
2020-01-21T22:24:01.0256480Z ##[debug]includeCurrentBuildDefinition=true
2020-01-21T22:24:01.0256480Z ##[debug]blockingBuildsList=null
2020-01-21T22:24:01.0412531Z ##[debug]blockInProgressBuilds=false
2020-01-21T22:24:01.0412531Z ##[debug]dependentOnSuccessfulBuildCondition=false
2020-01-21T22:24:01.0412531Z ##[debug]dependentBuildsList=null
2020-01-21T22:24:01.0412531Z ##[debug]dependentOnFailedBuildCondition=false
2020-01-21T22:24:01.0412531Z ##[debug]dependentFailingBuildsList=null
2020-01-21T22:24:01.0412531Z ##[debug]failTaskIfConditionsAreNotFulfilled=true
2020-01-21T22:24:01.0412531Z Using current Collection Url
2020-01-21T22:24:01.0412531Z Using current Team Project
2020-01-21T22:24:01.0412531Z Team Project: My Team Project with ID f93d9bcd-7bb6-4de1-b610-c1046df087da
2020-01-21T22:24:01.0412531Z Server URL: http://mytfs2015:8080/tfs/DefaultCollection/
2020-01-21T22:24:01.0412531Z Trying to fetch authentication token from system...
2020-01-21T22:24:01.0412531Z Using OAuth Access Token
2020-01-21T22:24:01.1037713Z Finishing task: TriggerBuild

I expected to see something like Queued new Build for definition ... in the log.

All the singleversion 3.x builds don't work as expected with TFS 2015 Update 4. Either they produce that error message or the build definition isn't actually triggered.

The good news is that benjhuser.tfs-extensions-build-tasks-2.9.2.vsix works without issues.

Thank you.

huserben commented 4 years ago

Hi @icnocop

Is 3.1.0_preview older than 3.0.11 in "releases"? 3.1.0 should be newer than 3.0.11 :-)

You trigger it from within a Release definition?

Ok the log is very strange, as it seems to not fail but just "not do" anything. I'm glad that it works with 2.9.2, it could be that there are issues with the API used in the newer versions that are not implemented by TFS 2015...that's at least the only explanation I have.

icnocop commented 4 years ago

Hi @huserben.

TFS 2015 doesn't have separate concepts of "Build" and "Release" definitions.

image

... it could be that there are issues with the API used in the newer versions that are not implemented by TFS 2015

Yes, you are probably right.

Thank you.

icnocop commented 4 years ago

I noticed package.json is using "azure-devops-node-api": "^6.6.3".

API and TFS Mapping seems to indicate that v6.6.3 may not be compatible with earlier versions of TFS.

I'm wondering if azure-devops-node-api v0.7.0 can be used instead for greater compatibility?

This is probably also related to the azure-devops-node-api v6.6.3 referenced in package.json in TfsRestService.

Thank you.

icnocop commented 4 years ago

For reference, I'm getting a 404 Not Found error when trying to trigger a build on a different queue. See https://github.com/microsoft/azure-devops-node-api/issues/371

Should I create a new issue?

Thank you.

huserben commented 4 years ago

Thanks for this input, at least that brings some clarity about the (currently) supported versions of TFS.

I'm a bit hesitant to roll back to such an early version as I can't tell if it's fully compatible and I currently lack the time to thorougly test all the scenarios.

If you do need it (for example if you have not planned any upgrad of your TFS) I can try to look into it, but it might take a bit. If that's the case, yes please create a new issue