maikvandergaag / msft-extensions

Repository for extensions mainly used for Azure DevOps Extensions
https://msftplayground.com
MIT License
125 stars 81 forks source link

Version number counter oAuth not working #442

Closed bjornbouetsmith closed 2 years ago

bjornbouetsmith commented 2 years ago

Describe the issue Using PAT works great. When using the new oAuth system - it seems like the code adds a '.' after the url - so whatever version I chose in the drop down for the API version - I get the following error:

Invoking rest method 'Get' for the url: http://devops.root.dom/ROOT/common/_apis/build/builds/541?api-version=5.1.
##[error]Unable to find a build definition for Project common with the build id: 541.

Extension

To Reproduce Steps to reproduce the behavior:

  1. Check 'Use system oAuth token'
  2. Select any version in the drop down 'API Version'

Expected behavior Version number gets updated - just like when using a PAT

Situation (please complete the following information):

maikvandergaag commented 2 years ago

The . is something in the extension. When using the OAuth system token. The build identity: Project Collection Build Service ({OrgName}) should have the permissions to see the pipelines and you should also make sure to make the accesstoken available in the flow.

https://msftplayground.com/2022/02/version-number-counter-now-supports-the-build-identity/

The above article shows an example with one of my other extensions

bjornbouetsmith commented 2 years ago

Hmm,

I have tried the following:

image

I have this:

image

And: image

But it just fails every time - this time though it does not say 'Unauthorized' - it just says it cannot find the build.

##[error]Unable to find a build definition for Project common with the build id: 571.

Any other hints?

bjornbouetsmith commented 2 years ago

Also - if I take the example script from microsoft and tweak it a little:

$build =  Invoke-RestMethod -Uri 'http://devops.root.dom/ROOT/common/_apis/build/builds/568?api-version=5.1' -Headers @{
    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "Build= $($build | ConvertTo-Json -Depth 100)"

It just works - so the access token is working it seems - even accessing the exact same url your extension tries to access.

This script I have set to run immediately before "version number counter"

maikvandergaag commented 2 years ago

Could you share the complete logs with a system.debug variable added with the value true

bjornbouetsmith commented 2 years ago

2022-09-22T17:44:59.7692962Z ##[debug]Evaluating condition for step: 'Increment version number' 2022-09-22T17:44:59.7695122Z ##[debug]Evaluating: succeeded() 2022-09-22T17:44:59.7695808Z ##[debug]Evaluating succeeded: 2022-09-22T17:44:59.7697219Z ##[debug]=> True 2022-09-22T17:44:59.7698387Z ##[debug]Result: True 2022-09-22T17:44:59.7699338Z ##[section]Starting: Increment version number 2022-09-22T17:44:59.7829171Z ============================================================================== 2022-09-22T17:44:59.7830115Z Task : Version number counter 2022-09-22T17:44:59.7831012Z Description : Build and release task for a version number counter 2022-09-22T17:44:59.7831715Z Version : 2.0.10 2022-09-22T17:44:59.7832432Z Author : Maik van der Gaag 2022-09-22T17:44:59.7833142Z Help : 2022-09-22T17:44:59.7833870Z ============================================================================== 2022-09-22T17:45:00.9230141Z ##[debug]VstsTaskSdk 0.1 commit _COMMITHASH 2022-09-22T17:45:01.0488862Z ##[debug]Entering D:\agent1_work_tasks\versioncounter_84f23c57-8c65-4709-bc94-5cbd44e96a99\2.0.10\run-task.ps1. 2022-09-22T17:45:01.0904085Z ##[debug]INPUT_VERSIONVARIABLE: 'Version' 2022-09-22T17:45:01.0972938Z ##[debug]INPUT_UPDATEMINORVERSION: 'false' 2022-09-22T17:45:01.1006339Z ##[debug]INPUT_MAXVALUEPATCHVERSION: '0' 2022-09-22T17:45:01.1039544Z ##[debug]INPUT_MAXVALUEMINORVERSION: '0' 2022-09-22T17:45:01.1073993Z ##[debug]INPUT_UPDATEMAJORVERSION: 'false' 2022-09-22T17:45:01.1108772Z ##[debug]INPUT_ONLYUPDATEMINOR: 'false' 2022-09-22T17:45:01.1170022Z ##[debug] Converted to bool: False 2022-09-22T17:45:01.1230370Z ##[debug]INPUT_DEVOPSPAT: '' 2022-09-22T17:45:01.1274304Z ##[debug]INPUT_USESYSTEMACCESSTOKEN: 'true' 2022-09-22T17:45:01.1299390Z ##[debug] Converted to bool: True 2022-09-22T17:45:01.1330318Z ##[debug]INPUT_BUILDAPIVERSION: '6.0' 2022-09-22T17:45:01.1364479Z VersionVariable : Version 2022-09-22T17:45:01.1366456Z UpdateMinorVersion : false 2022-09-22T17:45:01.1371856Z MaxValuePatchVersion : 0 2022-09-22T17:45:01.1374777Z UpdateMajorVersion : false 2022-09-22T17:45:01.1376996Z MaxValueMinorVersion : 0 2022-09-22T17:45:01.1408276Z DevOpsPAT : *** 2022-09-22T17:45:01.1412902Z DevOps Uri : http://devops.root.dom/ROOT/ 2022-09-22T17:45:01.1418571Z Project Name : common 2022-09-22T17:45:01.1420962Z Project Id : aabfc036-7e22-4e91-817c-fac427f61918 2022-09-22T17:45:01.1422663Z Only Update Minor : False 2022-09-22T17:45:01.1427210Z API Version : 6.0 2022-09-22T17:45:01.1431195Z BuildId : 592 2022-09-22T17:45:01.1456098Z Invoking rest method 'Get' for the url: http://devops.root.dom/ROOT/common/_apis/build/builds/592?api-version=6.0. 2022-09-22T17:45:01.1702866Z ##[debug]GET http://devops.root.dom/ROOT/common/_apis/build/builds/592?api-version=6.0 with 0-byte payload 2022-09-22T17:45:01.2268965Z ##[debug]received 4461-byte response of content type application/json; charset=utf-8; api-version=6.0 2022-09-22T17:45:01.2424523Z 2022-09-22T17:45:01.2515057Z ##[debug]Caught exception from task script. 2022-09-22T17:45:01.2558199Z ##[debug]Error record: 2022-09-22T17:45:01.3440857Z ##[debug]D:\agent1_work_tasks\versioncounter_84f23c57-8c65-4709-bc94-5cbd44e96a99\2.0.10\run-task.ps1 : Unable to find a build definition for Project common with the build id: 592. 2022-09-22T17:45:01.3473806Z ##[debug]At line:1 char:1 2022-09-22T17:45:01.3502324Z ##[debug]+ . 'D:\agent1_work_tasks\versioncounter_84f23c57-8c65-4709-bc94-5cbd ... 2022-09-22T17:45:01.3528681Z ##[debug]+ ~~~~~~~~~~~~~~~~~ 2022-09-22T17:45:01.3550081Z ##[debug] + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException 2022-09-22T17:45:01.3569808Z ##[debug] + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,run-task.ps1 2022-09-22T17:45:01.3594712Z ##[debug] 2022-09-22T17:45:01.3623112Z ##[debug]Script stack trace: 2022-09-22T17:45:01.3680049Z ##[debug]at , D:\agent1_work_tasks\versioncounter_84f23c57-8c65-4709-bc94-5cbd44e96a99\2.0.10\run-task.ps1: line 150 2022-09-22T17:45:01.3700044Z ##[debug]at , : line 1 2022-09-22T17:45:01.3723193Z ##[debug]at , : line 22 2022-09-22T17:45:01.3747909Z ##[debug]at , : line 18 2022-09-22T17:45:01.3773325Z ##[debug]at , : line 1 2022-09-22T17:45:01.3804017Z ##[debug]Exception: 2022-09-22T17:45:01.3873638Z ##[debug]Microsoft.PowerShell.Commands.WriteErrorException: Unable to find a build definition for Project common with the build id: 592. 2022-09-22T17:45:01.4294337Z ##[error]Unable to find a build definition for Project common with the build id: 592. 2022-09-22T17:45:01.4310123Z ##[debug]Processed: ##vso[task.logissue type=error]Unable to find a build definition for Project common with the build id: 592. 2022-09-22T17:45:01.4321604Z ##[debug]Processed: ##vso[task.complete result=Failed] 2022-09-22T17:45:01.4529604Z ##[section]Finishing: Increment version number

maikvandergaag commented 2 years ago

Hi Bjorn please remove the log or change it. Currently it it showing your PAT.

Another thing that I noticed it that you are using a on prem Azure DevOps. Will check it further for you

bjornbouetsmith commented 2 years ago

Hi, Yes I am using a on prem Azure DevOps - Azure DevOps Server 2020 Update 1.1

Regards