Answers: <p>You need to explicitly check out your source code, <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops" rel="nofollow noreferrer">because</a>:</p>
  <blockquote>
  <p>A deployment job doesn't automatically clone the source repo. You can checkout the source repo within your job with <code>checkout: self</code>. Deployment jobs only support one checkout step.</p>
  </blockquote>
  <pre><code>strategy:
    runOnce:
      deploy:
        steps:
  
        - checkout: self
        
        - task: Docker@2
          displayName: Build and push an image to container registry
          inputs:
            command: buildAndPush
            repository: $(imageRepository)
            dockerfile: $(Build.SourcesDirectory)/Dockerfile
            containerRegistry: $(dockerRegistryServiceConnection)
            tags: |
              $(tag)
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-05-03T18:16:49.970Z
Answers: 2022-05-09T21:15:13.087Z
Answers: 2022-05-09T21:15:13.087Z
Answers: Vince Bowdren
Body: <p>I'm trying to deploy a docker image to Azure Container Registry via an Azure Devops pipeline. Now this works fine when I run it with this script:</p>
  <pre><code>trigger:
  - master
  
  variables:
    # Container registry service connection established during pipeline creation
    dockerRegistryServiceConnection: 'some_id'
    imageRepository: 'worker'
    containerRegistry: 'microcontainerapptest.azurecr.io'
    dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
    tag: '$(Build.BuildId)'
  
    # Agent VM image name
    vmImageName: 'ubuntu-latest'
  
  stages:
  - stage: Build
    displayName: Build and push stage
    jobs:
    - job: Build
      displayName: Build
      pool:
        vmImage: $(vmImageName)
      steps:
      - task: Docker@2
        displayName: Build and push an image to container registry
        inputs:
          command: buildAndPush
          repository: $(imageRepository)
          dockerfile: $(dockerfilePath)
          containerRegistry: $(dockerRegistryServiceConnection)
          tags: |
            $(tag)
  </code></pre>
  <p>However, I want to actually use a deployment job so I can run the pipeline in different environments. Therefore I updated the .yml like this:</p>
  <pre><code>trigger:
  - master
  
  variables:
    # Container registry service connection established during pipeline creation
    dockerRegistryServiceConnection: 'some_id'
    imageRepository: 'worker'
    containerRegistry: 'microcontainerapptest.azurecr.io'
    dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
    tag: '$(Build.BuildId)'
  
    # Agent VM image name
    vmImageName: 'ubuntu-latest'
  
  stages:
  - stage: Build
    displayName: Build and push stage
    jobs:
    - deployment:
      displayName: Build docker image
      environment: $(DEPLOY_ENVIRONMENT)
      strategy:
        runOnce:
          deploy:
            steps:
            - task: Docker@2
              displayName: Build and push an image to container registry
              inputs:
                command: buildAndPush
                repository: $(imageRepository)
                dockerfile: $(Build.SourcesDirectory)/Dockerfile
                containerRegistry: $(dockerRegistryServiceConnection)
                tags: |
                  $(tag)
  </code></pre>
  <p>Making a deployment job out of this. Now when I run the pipeline like this I get an error</p>
  <blockquote>
  <p>Unhandled: No Dockerfile matching  /home/vsts/work/1/s/Dockerfile  was found.</p>
  </blockquote>
  <p>So it seems like the dockerfilePath is not valid anymore when I run it as a deployment job. I have searched but don't have a clue as to why this would be the case, does anybody know the answer to this?</p>
  
Tags: <docker><azure-devops><azure><azure-pipelines>
Title: Azure Devops deploy docker image to ACR using deployment job
UserDisplayName: Josh
ThreadText: # Azure Devops deploy docker image to ACR using deployment job
  
  (Asked by: username_0 on 2022-05-02)
  
  I'm trying to deploy a docker image to Azure Container Registry via an Azure Devops pipeline. Now this works fine when I run it with this script:
  
  ```
  trigger:
  - master
  
  variables:
    # Container registry service connection established during pipeline creation
    dockerRegistryServiceConnection: 'some_id'
    imageRepository: 'worker'
    containerRegistry: 'microcontainerapptest.azurecr.io'
    dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
    tag: '$(Build.BuildId)'
  
    # Agent VM image name
    vmImageName: 'ubuntu-latest'
  
  stages:
  - stage: Build
    displayName: Build and push stage
    jobs:
    - job: Build
      displayName: Build
      pool:
        vmImage: $(vmImageName)
      steps:
      - task: Docker@2
        displayName: Build and push an image to container registry
        inputs:
          command: buildAndPush
          repository: $(imageRepository)
          dockerfile: $(dockerfilePath)
          containerRegistry: $(dockerRegistryServiceConnection)
          tags: |
            $(tag)
  
  ```
  
  However, I want to actually use a deployment job so I can run the pipeline in different environments. Therefore I updated the .yml like this:
  
  ```
  trigger:
  - master
  
  variables:
    # Container registry service connection established during pipeline creation
    dockerRegistryServiceConnection: 'some_id'
    imageRepository: 'worker'
    containerRegistry: 'microcontainerapptest.azurecr.io'
    dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
    tag: '$(Build.BuildId)'
  
    # Agent VM image name
    vmImageName: 'ubuntu-latest'
  
  stages:
  - stage: Build
    displayName: Build and push stage
    jobs:
    - deployment:
      displayName: Build docker image
      environment: $(DEPLOY_ENVIRONMENT)
      strategy:
        runOnce:
          deploy:
            steps:
            - task: Docker@2
              displayName: Build and push an image to container registry
              inputs:
                command: buildAndPush
                repository: $(imageRepository)
                dockerfile: $(Build.SourcesDirectory)/Dockerfile
                containerRegistry: $(dockerRegistryServiceConnection)
                tags: |
                  $(tag)
  
  ```
  
  Making a deployment job out of this. Now when I run the pipeline like this I get an error
  
  > Unhandled: No Dockerfile matching /home/vsts/work/1/s/Dockerfile was found.
  
  So it seems like the dockerfilePath is not valid anymore when I run it as a deployment job. I have searched but don't have a clue as to why this would be the case, does anybody know the answer to this?
  
  **Tags:** docker, azure-devops, azure, azure-pipelines
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-05-03. Score: 0
  
  You need to explicitly check out your source code, [because](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops):
  
  > A deployment job doesn't automatically clone the source repo. You can checkout the source repo within your job with `checkout: self`. Deployment jobs only support one checkout step.
  
  ```
  strategy:
    runOnce:
      deploy:
        steps:
  
        - checkout: self
        
        - task: Docker@2
          displayName: Build and push an image to container registry
          inputs:
            command: buildAndPush
            repository: $(imageRepository)
            dockerfile: $(Build.SourcesDirectory)/Dockerfile
            containerRegistry: $(dockerRegistryServiceConnection)
            tags: |
              $(tag)
  
  ```
  
  
  ---
  
  