Azure DevOps VMSS代理CI管道中dotnet cyclonedx命令执行失败求助
问题:Azure DevOps VMSS代理中无法运行dotnet CycloneDX命令生成SBOM
在Azure DevOps CI流水线的PowerShell任务中使用VMSS代理生成SBOM,已通过dotnet tool install --global CycloneDX安装CycloneDX工具,但执行dotnet cyclonedx命令时报错:"Could not execute because the specified command or file was not found"。该问题与dotnet ef命令找不到的同类问题性质一致。
完全相同的YAML代码在托管代理/微软代理上可正常运行,远程登录VM实例通过PowerShell执行也无问题。已更新VM镜像模板中的.NET SDK,使其与Windows代理的运行时和SDK版本一致,且设置了dotnet环境变量,但问题仍未解决。
相关YAML代码(缩进正确)
- ${{ if eq(parameters.generateSbom, true) }}: - task: PowerShell@2 displayName: 'Install or Update CycloneDX' inputs: targetType: inline script: | # dotnet tool install --global CycloneDX dotnet tool update --global CycloneDX enabled: true - ${{ if eq(parameters.repositoryName, 'Project-Api') }}: - task: PowerShell@2 displayName: 'Execute CycloneDX' inputs: targetType: inline script: | echo '-- dotnet tools global --' dotnet tool list -g echo '-- dotnet tools local --' dotnet tool list --local echo '-- dotnet search cyclone --' dotnet tool search cyclone echo '-- dotnet info --' dotnet --info echo '-- dotnet run following cyclonedx --' echo 'command=dotnet CycloneDX $(Agent.BuildDirectory)\${{ parameters.repositoryName }}\${{ parameters.slnBuildPath }} o $(Agent.BuildDirectory)\${{ parameters.repositoryName }}\${{ parameters.testProjRootPath }}' dotnet CycloneDX '$(Agent.BuildDirectory)\${{ parameters.repositoryName }}\${{ parameters.slnBuildPath }}' -o '$(Agent.BuildDirectory)\${{ parameters.repositoryName }}\${{ parameters.testProjRootPath }}' # # try run cyclonedx from install folder path # $path = Join-Path -Path $($env:UserProfile) -ChildPath '/.dotnet/tools/dotnet-CycloneDX.exe' # Write-Host $path # path '$(Agent.BuildDirectory)\${{ parameters.repositoryName }}\${{ parameters.slnBuildPath }}' -o '$(Agent.BuildDirectory)\${{ parameters.repositoryName }}\${{ parameters.testProjRootPath }}' # pwsh: true enabled: true
构建流水线输出日志
Execute CycloneDX View raw log Starting: Execute CycloneDX ============================================================================== Task : PowerShell Description : Run a PowerShell script on Linux, macOS, or Windows Version : 2.212.0 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell ============================================================================== Generating script. ========================== Starting Command Output =========================== "C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\a\_temp\019379f0-2ab5-4e5f-9b88-f47f041a12a8.ps1'" -- dotnet tools global -- Package Id Version Commands --------------------------------------------- cyclonedx 2.7.0 dotnet-CycloneDX -- dotnet tools local -- Package Id Version Commands Manifest --------------------------------------------------- -- dotnet search cyclone -- Package ID Latest Version Authors Downloads Verified ------------------------------------------------------------------------------------------------ cyclonedx 2.7.0 Steve Springett & Patrick Dwyer 1107621 hades-cli 0.2.0 Patrik Svensson 1503 -- dotnet info -- .NET SDK: Version: 7.0.202 Commit: 6c74320bc3 Runtime Environment: OS Name: Windows OS Version: 10.0.20348 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.202\ Host: Version: 7.0.4 Architecture: x64 Commit: 0a396acafe .NET SDKs installed: 2.2.207 [C:\Program Files\dotnet\sdk] 3.1.120 [C:\Program Files\dotnet\sdk] 3.1.426 [C:\Program Files\dotnet\sdk] 6.0.114 [C:\Program Files\dotnet\sdk] 6.0.309 [C:\Program Files\dotnet\sdk] 6.0.406 [C:\Program Files\dotnet\sdk] 7.0.202 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download -- dotnet run following cyclonedx -- command=dotnet CycloneDX C:\a\1\[MySolutionPath\SolutionName].sln o C:\a\1\[MySbomOutputPath] Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a .NET program, but dotnet-CycloneDX does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH. ##[error]PowerShell exited with code '1'. Finishing: Execute CycloneDX
内容的提问来源于stack exchange,提问作者naderunner
相关产品推荐
相关产品推荐

