0

I am trying to generate an SBOM in a Azure Devops CI pipeline using a powershell task when the build agent is set to an VMSS agent. I cannot seem to run the dotnet cyclonedx command, after it has been installed using dotnet tool install --global CycloneDX.

I get the following error in the pipeline output: "Could not execute because the specified command or file was not found." This appears to be related to a similar Issue I found here and also here.

The exact same yaml code works when I run it on a hosted agent or microsoft agent but not on the VMSS. It also works when I remote into the VM instance and run it via powershell. I have updated the dotnet SDK's on the VM-image template to have the same runtimes and SDK's as the windows agent and set the environment path variables for dotnet to no avail.

Can anyone help? I am stumped why this simple thing is not working. Code and build output as follows:

YAML Code (indentation is correct in yaml pipeline)

- ${{ 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

build pipeline output:

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
naderunner
  • 41
  • 7
  • I don 't not think dotnet is fully installed. Need to config. See : https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet#see-also – jdweng Mar 28 '23 at 17:23
  • If dotnet is not fully installed, why does the command work when I remote into the VM instance in the VMSS and successfully run the cylonedx command via powershell? – naderunner Mar 29 '23 at 06:43

1 Answers1

0

It looks like I needed to explicitly specify the dotnet sdk to use in the yaml:

- task: UseDotNet@2
    inputs:
       packageType: 'sdk'
       version: '6.x'

Seems to be a bit of a mystery why it worked on azure build agent with dotnet 7 sdk without using the aforementioned. Seeing as of 2023-03-29 I looked like it is not supported yet. They could do with more detailed documentation.

The microsoft/sbom-tool documentation helped me with getting to this solution.

Hopefully this will help someone.

naderunner
  • 41
  • 7
  • Yaml probably is looking for a different version of Dot Net. Using a new version that is supported really means still using older version. – jdweng Mar 29 '23 at 08:45