Search code examples
azure-devopsazure-cli2

Pipeline Failed When Running Azure CLI Task


Good morning:

In Azure DevOps I'm setting up a pipeline that, based on a repository with a docker project (with a Docker-Compose file), automates the completion and publication of the service. The thing is that for the following task it gives me a route error:

  - task: AzureCLI@2
      displayName: Docker Build
      inputs:
        azureSubscription: '$(azureSubscriptionEndpoint)'
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: |
          docker build -t service:$(tag).
          docker save service:$(tag) -o service_$(tag).tar


/usr/bin/bash /home/vsts/work/_temp/azureclitaskscript1713529050063.sh
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2B done
#1 DONE 0.0s

#2 [internal] load .dockerignore

#2 transferring context: 2B done #2 DONE 0.0s ERROR: failed to solve: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount2163565617/Dockerfile: no such file or directory Error response from daemon: reference does not exist



I don't think he's looking for it in the right folder, but I don't know where to look for it or how. Any ideas?

This first part of the Pipeline looks like this (error en la tarea AzureCLI@2):


trigger:
- master

pool:
  vmImage: 'ubuntu-latest' 

variables:
  tag: 1.0.0-$(Build.BuildId)
  buildConfiguration: 'Release'
  acrINT: 'XXXXX'
  aKSINT: 'XXXXX'
  azureSubscriptionEndpoint: 'XXXXXX'
  azureContainerRegistry: 'XXXXX'
  dockerComposeFile: 'docker-compose.yml'
  resourceGroupName: ''
  clusterName: ''


stages:
- stage: Build
  displayName: Build 
  jobs:
  - job: Build_code
    displayName: Build 
    pool:
      vmImage: 'ubuntu-latest'

    steps:
    - task: UseDotNet@2
      displayName: 'Install .NET Core SDK'
      inputs:
        version: 8.x
        performMultiLevelLookup: true
        includePreviewVersions: true # Required for preview versions

    - task: DotNetCoreCLI@2
      inputs:
        command: 'build'
        projects: '**/*.csproj'

    - task: DockerCompose@0
      inputs:
        workingDirectory: '$(System.DefaultWorkingDirectory)'
        containerregistrytype: 'Azure Container Registry'
        azureSubscription: '$(azureSubscriptionEndpoint)'
        azureContainerRegistry: '$(azureContainerRegistry)'
        dockerComposeFile: '$(dockerComposeFile)'
        additionalDockerComposeFiles: 'docker-compose.override.yml'
        dockerComposeFileArgs: 'DOCKER_BUILD_SOURCE='
        action: 'Run a Docker Compose command'
        dockerComposeCommand: 'build --parallel'

    - task: AzureCLI@2
      displayName: Docker Build
      inputs:
        azureSubscription: '$(azureSubscriptionEndpoint)'
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: |
          docker build -t service:$(tag) .
          docker save service:$(tag) -o service_$(tag).tar


    - task: PublishPipelineArtifact@1
      inputs:
        targetPath: '$(Pipeline.Workspace)'
        artifact: 'service-artifact'
        publishLocation: 'pipeline'`

Ejecutar el Pipeline y que se cree el servicio

Solution

  • The error indicates the Dockerfile is not found under the default working directory. Please follow below items for a check:

    1. Docker is case-sensitive. Ensure that the Dockerfile is named exactly as Dockerfile (without any extension) and not dockerFile.

    2. Check which repo and branch is the pipeline build is running on, confirm the Dockerfile exists on the correct repo and branch.

    If the issue persists, it's recommended to find Dockerfile(find . -name "Dockerfile" ) before build: enter image description here

    If Dockerfile is not under root directory, you can add workingDirectory for the task:

    - task: AzureCLI@2
      displayName: Docker Build
      inputs:
        azureSubscription: '$(azureSubscriptionEndpoint)'
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: |
          find . -name "Dockerfile"             # try to find the Dockerfile before build.
          docker build -t service:$(tag) .
          docker save service:$(tag) -o service_$(tag).tar
        workingDirectory: Docker                # the Dockerfile folder