通过Azure DevOps流水线锁定分支时遇404错误求助
Azure DevOps流水线分支锁定404错误解决方法
问题描述
在Azure DevOps流水线中执行分支锁定命令时,出现以下404错误:
ERROR: The controller for path '/obisvt/_apis' was not found or does not implement IController. Operation returned a 404 status code.
流水线配置代码如下:
trigger: none appendCommitMessageToRunName: false pool: vmImage: 'ubuntu-latest' steps: - task: UsePythonVersion@0 inputs: versionSpec: '3.x' # Required to use Azure CLI - task: UseDotNet@2 # Ensures .NET is available if needed inputs: packageType: 'sdk' version: '6.0.302' - bash: echo ${AZURE_DEVOPS_CLI_PAT} | az devops login env: AZURE_DEVOPS_CLI_PAT: $(System.AccessToken) displayName: 'Login Azure DevOps Extension' - script: az repos ref lock --repository "test" --org "https://dev.azure.com/test/project1" --project "OBISVT" --name "main_test"
解决步骤
1. 修正组织URL格式
--org参数只需填写Azure DevOps组织的根URL,不需要包含项目路径。原命令中的https://dev.azure.com/test/project1错误,应改为https://dev.azure.com/test。
2. 补充分支完整引用路径
--name参数需要指定分支的完整引用格式,即refs/heads/<分支名>。原命令中的main_test应改为refs/heads/main_test。
3. (可选)验证权限
确保流水线使用的System.AccessToken对应的服务账号,对目标仓库拥有Manage branches权限,否则即使命令格式正确,也会因权限不足执行失败。
修改后的正确脚本
将最后一步的script任务替换为:
az repos ref lock --repository "test" --org "https://dev.azure.com/test" --project "OBISVT" --name "refs/heads/main_test"
内容的提问来源于stack exchange,提问作者Ukchat
相关产品推荐
相关产品推荐

