huserben / TfsExtensions

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

Handle Validation Errors when triggering Build #26

Closed thoemmi closed 6 years ago

thoemmi commented 6 years ago

I tried the Trigger Build task (v2.1) with my VSTS repository. Unfortunately, it does not trigger a build. In the log of the task you see this line Queued new Build for definition EchoBuild: https://thoemmi.visualstudio.com/Demo/_build/index?buildId=undefined. To me it looks like the task is not able to determine the id of the build definition "EchoBuild".

Here's the complete log of the task with system.debug="true". Is there any other information I can provide you with to narrow it down?

2017-09-11T14:30:11.7551590Z ##[debug]Evaluating condition for step: 'Trigger a new build of EchoBuild'
2017-09-11T14:30:11.7561381Z ##[debug]Evaluating: succeeded()
2017-09-11T14:30:11.7561381Z ##[debug]Evaluating succeeded:
2017-09-11T14:30:11.7561381Z ##[debug]=> (Boolean) True
2017-09-11T14:30:11.7561381Z ##[debug]Expanded: True
2017-09-11T14:30:11.7561381Z ##[debug]Result: True
2017-09-11T14:30:11.7561381Z ##[section]Starting: Trigger a new build of EchoBuild
2017-09-11T14:30:11.7561381Z ==============================================================================
2017-09-11T14:30:11.7561381Z Task         : Trigger Build
2017-09-11T14:30:11.7561381Z 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.
2017-09-11T14:30:11.7561381Z Version      : 2.1.0
2017-09-11T14:30:11.7561381Z Author       : Benjamin Huser
2017-09-11T14:30:11.7561381Z Help         : 
2017-09-11T14:30:11.7561381Z ==============================================================================
2017-09-11T14:30:11.9404847Z ##[debug]agent.workFolder=d:\a
2017-09-11T14:30:11.9434849Z ##[debug]loading inputs and endpoints
2017-09-11T14:30:11.9444845Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2017-09-11T14:30:11.9454851Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2017-09-11T14:30:11.9454851Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2017-09-11T14:30:11.9454851Z ##[debug]loading INPUT_AUTHENTICATIONMETHOD
2017-09-11T14:30:11.9454851Z ##[debug]loading INPUT_BUILDDEFINITION
2017-09-11T14:30:11.9454851Z ##[debug]loading INPUT_DEFINITIONISINCURRENTTEAMPROJECT
2017-09-11T14:30:11.9454851Z ##[debug]loading INPUT_DEPENDENTONFAILEDBUILDCONDITION
2017-09-11T14:30:11.9464844Z ##[debug]loading INPUT_DEPENDENTONSUCCESSFULBUILDCONDITION
2017-09-11T14:30:11.9464844Z ##[debug]loading INPUT_DOWNLOADBUILDARTIFACTS
2017-09-11T14:30:11.9464844Z ##[debug]loading INPUT_DROPDIRECTORY
2017-09-11T14:30:11.9464844Z ##[debug]loading INPUT_ENABLEBUILDINQUEUECONDITION
2017-09-11T14:30:11.9464844Z ##[debug]loading INPUT_FAILTASKIFBUILDSNOTSUCCESSFUL
2017-09-11T14:30:11.9464844Z ##[debug]loading INPUT_IGNORESSLCERTIFICATEERRORS
2017-09-11T14:30:11.9464844Z ##[debug]loading INPUT_INCLUDECURRENTBUILDDEFINITION
2017-09-11T14:30:11.9474846Z ##[debug]loading INPUT_QUEUEBUILDFORUSERTHATTRIGGEREDBUILD
2017-09-11T14:30:11.9474846Z ##[debug]loading INPUT_STOREINENVIRONMENTVARIABLE
2017-09-11T14:30:11.9474846Z ##[debug]loading INPUT_USESAMEBRANCH
2017-09-11T14:30:11.9474846Z ##[debug]loading INPUT_USESAMESOURCEVERSION
2017-09-11T14:30:11.9474846Z ##[debug]loading INPUT_WAITFORQUEUEDBUILDSTOFINISH
2017-09-11T14:30:11.9474846Z ##[debug]loading INPUT_WAITFORQUEUEDBUILDSTOFINISHREFRESHTIME
2017-09-11T14:30:11.9484848Z ##[debug]loaded 20
2017-09-11T14:30:12.1514849Z ##[debug]definitionIsInCurrentTeamProject=true
2017-09-11T14:30:12.1514849Z ##[debug]tfsServer=null
2017-09-11T14:30:12.1514849Z ##[debug]buildDefinition=EchoBuild
2017-09-11T14:30:12.1514849Z ##[debug]ignoreSslCertificateErrors=false
2017-09-11T14:30:12.1524850Z ##[debug]queueBuildForUserThatTriggeredBuild=true
2017-09-11T14:30:12.1524850Z ##[debug]useSameSourceVersion=false
2017-09-11T14:30:12.1524850Z ##[debug]useSameBranch=true
2017-09-11T14:30:12.1524850Z ##[debug]branchToUse=null
2017-09-11T14:30:12.1524850Z ##[debug]waitForQueuedBuildsToFinish=false
2017-09-11T14:30:12.1524850Z ##[debug]waitForQueuedBuildsToFinishRefreshTime=60
2017-09-11T14:30:12.1524850Z ##[debug]failTaskIfBuildsNotSuccessful=true
2017-09-11T14:30:12.1534851Z ##[debug]downloadBuildArtifacts=false
2017-09-11T14:30:12.1534851Z ##[debug]dropDirectory=d:\a
2017-09-11T14:30:12.1534851Z ##[debug]storeInEnvironmentVariable=false
2017-09-11T14:30:12.1534851Z ##[debug]buildParameters=null
2017-09-11T14:30:12.1534851Z ##[debug]authenticationMethod=OAuth Token
2017-09-11T14:30:12.1534851Z ##[debug]username=null
2017-09-11T14:30:12.1534851Z ##[debug]password=null
2017-09-11T14:30:12.1534851Z ##[debug]enableBuildInQueueCondition=false
2017-09-11T14:30:12.1534851Z ##[debug]includeCurrentBuildDefinition=true
2017-09-11T14:30:12.1534851Z ##[debug]blockingBuildsList=null
2017-09-11T14:30:12.1534851Z ##[debug]dependentOnSuccessfulBuildCondition=false
2017-09-11T14:30:12.1534851Z ##[debug]dependentBuildsList=null
2017-09-11T14:30:12.1534851Z ##[debug]dependentOnFailedBuildCondition=false
2017-09-11T14:30:12.1534851Z ##[debug]dependentFailingBuildsList=null
2017-09-11T14:30:12.1554847Z Using current Team Project Url
2017-09-11T14:30:12.1554847Z Path to Server: https://thoemmi.visualstudio.com/Demo
2017-09-11T14:30:12.1554847Z Using OAuth Access Token
2017-09-11T14:30:12.1564846Z Trying to fetch authentication token from system...
2017-09-11T14:30:12.1564846Z Build shall be triggered for same user that triggered current build: Thomas Freudenberg
2017-09-11T14:30:12.1564846Z Using same branch as source version: $/Demo
2017-09-11T14:30:12.4899079Z Queue new Build for definition EchoBuild
2017-09-11T14:30:12.5812817Z Queued new Build for definition EchoBuild: https://thoemmi.visualstudio.com/Demo/_build/index?buildId=undefined
2017-09-11T14:30:12.5846465Z ##[section]Finishing: Trigger a new build of EchoBuild
huserben commented 6 years ago

Hi @thoemmi

yes it seems that it for some reason cannot figure out the id of the build. I'll put it on my todo list that I will fail the task when this happens and have a better logging around this.

Now the question is why this happens, looking the code there is actually a check when we try to get the build id for the name:

if (result.count === 0) {
    throw new Error(`Did not find any build definition with this name: ${buildDefinitionName}
    - checked following url: ${options.baseUrl}${requestUrl}`);
}

apparently this is still ok but then return result.value[0].id; returns undefined...

Could you try to query your TFS in a browser and post the resulting JSON. The url would be (given your demo data) like this: https://thoemmi.visualstudio.com/DefaultCollection/Demo/_apsi/build/definitions?api-version=2.0&name=EchoBuild

thoemmi commented 6 years ago

Hello @huserben, I've identified the issue: In the secondary build definition, EchoBuild, an empty agent queue was configured. Because of this no build can be queued automatically. If I queue a build manually, I have to change the agent queue. I changed the build definition to use a working agent queue, and your build task was able to queue a new build. So no issue on your side 😉

I don't close this issue now because I don't know if you want to keep it open as a reference, in case you plan to improve the error handling.

huserben commented 6 years ago

Hi

alright cool, good to know and probably something to put into the documentation at least :-) I will keep it open for reference and maybe I can even figure out this situation and fail if this is the case.

Anyway thanks for reporting this and helping on improve the Task.

thoemmi commented 6 years ago

I started my own implementation a couple of weeks ago, until I stumbled over your task recently. It's more feature-rich than mine, so I dropped my attempt. Thanks for sharing your awesome task :+1:

huserben commented 6 years ago

Thanks for the nice words 👍

I looked at the problem with the empty agent queue and added a general error handling which is checked after we triggered the build. There is a general validation concept and I will fail the Task if there are any validation errors: grafik

The messages I display I take directly from the response I get from TFS (see here an example viewed in Postman): grafik

This generic approach has the advantage that we can generally handle problems that might arise when triggering the build, however the error message provided might not be so specific.

I will check this change during this week. Thanks again for your help in identifying the issue.

huserben commented 6 years ago

Hi

I just updated the Task to version 2.2 which adds the proper validation output.