Friday, April 3, 2020

dotnet ef is Failing in Azure DevOps Pipeline When the Agent is ubuntu-latest

I was trying to run dotnet ef command within Azure DevOps Pipeline and it's failing with the error: Could not execute because the specified command or file was not found. This is even after installing the dotnet ef tool.
trigger:
- master
 
resources:
- repo: self
 
variables:
  vmImageName: 'ubuntu-latest'
 
stages:
 
- stage: Build
  displayName: Build and push stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: DotNetCoreCLI@2
      displayName: Install dotnet-ef
      inputs:
        command: 'custom'
        custom: 'tool'
        arguments: 'install --global dotnet-ef'
    - task: DotNetCoreCLI@2
      displayName: Check dotnet-ef version
      inputs:
        command: 'custom'
        custom: 'ef'
        arguments: '--version'
So here I have 2 tasks, in the first task is I am installing dotnet-ef and in the second task, I am just checking the version.

This is failing with the error: Could not execute because the specified command or file was not found.

The reason turned out to be, we need to use the UseDotnet@2 task first, to install the dotnet sdk and then install the dotnet ef. This will make dotnet-ef installed into same path as of dotnet sdk and will make it able to execute.
Use .NET Core
trigger:
- master
 
resources:
- repo: self
 
variables:
  vmImageName: 'ubuntu-latest'
 
stages:
 
- stage: Build
  displayName: Build
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: UseDotNet@2
      inputs:
        version: '3.1.200'
    - task: DotNetCoreCLI@2
      displayName: Install dotnet-ef
      inputs:
        command: 'custom'
        custom: 'tool'
        arguments: 'install --global dotnet-ef'
    - task: DotNetCoreCLI@2
      displayName: Check dotnet-ef version
      inputs:
        command: 'custom'
        custom: 'ef'
        arguments: '--version'
So this works. Hope this helps!

Happy Coding.

Regards,
Jaliya

No comments:

Post a Comment