huserben / TfsExtensions

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

Authentication with TFS Server failed with Personal Token #39

Closed yuraku closed 6 years ago

yuraku commented 6 years ago

Hi. For some reason, authentication is failed using personal token.

2017-12-06T13:21:28.7710680Z Using Custom Team Project Url 2017-12-06T13:21:28.7711301Z Path to Server: ${project.url} 2017-12-06T13:21:28.7718183Z Using Personal Access Token 2017-12-06T13:21:28.8271898Z Authentication failed - please make sure your settings are correct. 2017-12-06T13:21:28.8272647Z If you use the OAuth Token, make sure you enabled the access to it on the Build Definition. 2017-12-06T13:21:28.8272806Z If you use a Personal Access Token, make sure it did not expire. 2017-12-06T13:21:28.8272948Z If you use Basic Authentication, make sure alternate credentials are enabled on your TFS/VSTS. 2017-12-06T13:21:28.8351768Z ##[error]Authentication with TFS Server failed. Please check your settings.

In configuration: "Authentication Method -> Personal Access Token" and generated previously token was provided.

huserben commented 6 years ago

Hi

the Personal Access Token will expire after a certain amount of time (90 days to 1 year or so). Is it possible that this has happened? You should see in the overview of your tokens whether it is expired or not.

yuraku commented 6 years ago

Hi @huserben. Thanks for a quick reply. I've just created a token for a 1 year, so token is fresh. Also, I've tried username/password and result is the same. All configurations are in scope of one project. The goal is to run two builds with tests from the same project one after another

huserben commented 6 years ago

Hi

ok sorry then I missunderstood, I assumed it was working once but then stopped. What scopes did you authorize the token to be used for? I think at least you need to enable Build (read and execute):

grafik

In case that's not working you can as well try to temporarily authorize it for all scopes. If that does not work there is some other issue.

yuraku commented 6 years ago

I've tried both cases (all scopes and only Build). Also checked that access token for all projects. Is there any chance to debug auth process? Also I've tried that other build should be triggered for the same user as the first one.

huserben commented 6 years ago

hmm ok, that's strange.

Can you in order to check if the problem is within the PAT try to use OAuth Authentication? Just empty the password field and make sure the build definition has access to the token (in the options tab of the build you can set "Allow scripts to access OAuth token").

yuraku commented 6 years ago

Already did. Result is the same.

huserben commented 6 years ago

can run it with the debug parameter set to true and send me the log file so I can see all the options selected etc.? (of course just change the parts i'm not supposed to see like the concrete url, project name etc.)

yuraku commented 6 years ago

Logs for username/password: `** Starting: Trigger a new build of PROJECT-QA-TEST


============================================================================== 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 : 2.4.3 Author : Benjamin Huser Help :

agent.TempDirectory=d:\a_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_BUILDDEFINITION loading INPUT_DEFINITIONISINCURRENTTEAMPROJECT loading INPUT_DEPENDENTBUILDSLIST loading INPUT_DEPENDENTONFAILEDBUILDCONDITION loading INPUT_DEPENDENTONSUCCESSFULBUILDCONDITION loading INPUT_DOWNLOADBUILDARTIFACTS loading INPUT_DROPDIRECTORY loading INPUT_ENABLEBUILDINQUEUECONDITION loading INPUT_FAILTASKIFBUILDSNOTSUCCESSFUL loading INPUT_IGNORESSLCERTIFICATEERRORS loading INPUT_INCLUDECURRENTBUILDDEFINITION loading INPUT_PASSWORD loading INPUT_QUEUEBUILDFORUSERTHATTRIGGEREDBUILD loading INPUT_STOREINENVIRONMENTVARIABLE loading INPUT_TFSSERVER loading INPUT_USERNAME loading INPUT_USESAMEBRANCH loading INPUT_USESAMESOURCEVERSION loading INPUT_WAITFORQUEUEDBUILDSTOFINISH loading INPUT_WAITFORQUEUEDBUILDSTOFINISHREFRESHTIME loaded 24 Agent.ProxyUrl=undefined Agent.CAInfo=undefined Agent.ClientCert=undefined definitionIsInCurrentTeamProject=false tfsServer=${TFS_SERVER_URL} buildDefinition=PROJECT-QA-TEST ignoreSslCertificateErrors=false queueBuildForUserThatTriggeredBuild=false useSameSourceVersion=false useSameBranch=false branchToUse=null waitForQueuedBuildsToFinish=true waitForQueuedBuildsToFinishRefreshTime=10 failTaskIfBuildsNotSuccessful=true downloadBuildArtifacts=false dropDirectory=d:\a storeInEnvironmentVariable=false demands=null queueid=null buildParameters=null authenticationMethod=Basic Authentication username=${tfs_username} password=${tfs_password} enableBuildInQueueCondition=false includeCurrentBuildDefinition=true blockingBuildsList=null dependentOnSuccessfulBuildCondition=false dependentBuildsList=PROJECT-QA-TEST dependentOnFailedBuildCondition=false dependentFailingBuildsList=null Using Custom Team Project Url Path to Server: ${SERVER_URL} Using Basic Authentication Authentication failed - please make sure your settings are correct. If you use the OAuth Token, make sure you enabled the access to it on the Build Definition. If you use a Personal Access Token, make sure it did not expire. If you use Basic Authentication, make sure alternate credentials are enabled on your TFS/VSTS. task result: Failed Authentication with TFS Server failed. Please check your settings. Processed: ##vso[task.issue type=error;]Authentication with TFS Server failed. Please check your settings. Processed: ##vso[task.complete result=Failed;]Authentication with TFS Server failed. Please check your settings.


Finishing: Trigger a new build of PROJECT-QA-TEST **`

Logs for personal access token: `** Starting: Trigger a new build of PROJECT-QA-TEST


============================================================================== 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 : 2.4.3 Author : Benjamin Huser Help :

agent.TempDirectory=d:\a_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_BUILDDEFINITION loading INPUT_DEFINITIONISINCURRENTTEAMPROJECT loading INPUT_DEPENDENTBUILDSLIST loading INPUT_DEPENDENTONFAILEDBUILDCONDITION loading INPUT_DEPENDENTONSUCCESSFULBUILDCONDITION loading INPUT_DOWNLOADBUILDARTIFACTS loading INPUT_DROPDIRECTORY loading INPUT_ENABLEBUILDINQUEUECONDITION loading INPUT_FAILTASKIFBUILDSNOTSUCCESSFUL loading INPUT_IGNORESSLCERTIFICATEERRORS loading INPUT_INCLUDECURRENTBUILDDEFINITION loading INPUT_PASSWORD loading INPUT_QUEUEBUILDFORUSERTHATTRIGGEREDBUILD loading INPUT_STOREINENVIRONMENTVARIABLE loading INPUT_TFSSERVER loading INPUT_USERNAME loading INPUT_USESAMEBRANCH loading INPUT_USESAMESOURCEVERSION loading INPUT_WAITFORQUEUEDBUILDSTOFINISH loading INPUT_WAITFORQUEUEDBUILDSTOFINISHREFRESHTIME loaded 24 Agent.ProxyUrl=undefined Agent.CAInfo=undefined Agent.ClientCert=undefined definitionIsInCurrentTeamProject=false tfsServer=${TFS_SERVER_URL} buildDefinition=PROJECT-QA-TEST ignoreSslCertificateErrors=false queueBuildForUserThatTriggeredBuild=false useSameSourceVersion=false useSameBranch=false branchToUse=null waitForQueuedBuildsToFinish=true waitForQueuedBuildsToFinishRefreshTime=10 failTaskIfBuildsNotSuccessful=true downloadBuildArtifacts=false dropDirectory=d:\a storeInEnvironmentVariable=false demands=null queueid=null buildParameters=null authenticationMethod=Personal Access Token username=${USERNAME} password=${PERSONAL_ACCESS_TOKEN} enableBuildInQueueCondition=false includeCurrentBuildDefinition=true blockingBuildsList=null dependentOnSuccessfulBuildCondition=false dependentBuildsList=PROJECT-QA-TEST dependentOnFailedBuildCondition=false dependentFailingBuildsList=null Using Custom Team Project Url Path to Server: ${TFS_SERVER_URL} Using Personal Access Token Authentication failed - please make sure your settings are correct. If you use the OAuth Token, make sure you enabled the access to it on the Build Definition. If you use a Personal Access Token, make sure it did not expire. If you use Basic Authentication, make sure alternate credentials are enabled on your TFS/VSTS. task result: Failed Authentication with TFS Server failed. Please check your settings. Processed: ##vso[task.issue type=error;]Authentication with TFS Server failed. Please check your settings. Processed: ##vso[task.complete result=Failed;]Authentication with TFS Server failed. Please check your settings.


Finishing: Trigger a new build of PROJECT-QA-TEST **`

huserben commented 6 years ago

I see you used a custom TFS URL. Can you ensure that this URL is correct, meaning it has the URL to tfs including the Collection (its always DefaultCollection if VSTS is used) and the name of the actual TeamProject. If it is a different TFS than the one that runs the original build, make sure the access token/basic authentication is enabled on this tfs server and not on the original one that triggeres the build.

yuraku commented 6 years ago

I found the problem. In my case project named with spaces, "QA - TEST" and was copied with '%20' instead of spaces in the url. And during auth process, it was not working.

huserben commented 6 years ago

Hi @yuraku

very good. I will close the issue then. Thanks for your feedback.