Good afternoon,

I am building a CI pipeline in Azure DevOps which is new ground for me. I managed to create add the build tasks en steps that I wanted. Although there still are some issues. I explain those issues down here.

Issue #1

I misunderstood the meaning of the latest tag. I thought it would automatically pull the latest/newest version from the specified Docker Hub.

Currently my Docker build looks like this:

```
- task: Docker@2
  displayName: 'Build Docker image'
  inputs:
    repository: '<my_repo_name>'
    command: 'build'
    Dockerfile: '**/Dockerfile'
    tags: $(Build.BuildId)

```

This pipeline YAML is to deploy to my production VPS which I added under Pipelines -> Environments.
Here is the deployment step of the pipeline:

```
- deployment: VMDeploy
  displayName: 'Deployment to VPS'
  pool:
    vmImage: 'Ubuntu-20.04'
  environment:
   name: CDB_VPS
   resourceName: <my_resource_name>
   resourceType: VirtualMachine
  strategy:
    runOnce:
      deploy:
        steps:
        - script: docker pull <my_repo_name>:latest
        - script: docker stop $(docker ps -aq)
        - script: docker run -p 8085:8085 <my_repo_name>:latest

```

Issue #2
I do not get any errors in the pipeline while running it. But I am wondering if this is a good practice. By using this it will always run version latest. Also I don't think this is how I should deploy.

Issue #3
The deployment block gets executed before the build and push block is finished. To give extra information I will post the entire YAML file down here.

```
trigger:
- master
jobs:
- job: Build
  displayName: 'Build Maven project and Docker build'
  steps:
    - task: replacetokens@3
      displayName: 'Replace tokens'
      inputs:
        targetFiles: |
          **/application.properties
    - task: Maven@3
      displayName: 'Build Maven project'
      inputs:
        mavenPomFile: 'pom.xml'
        goals: 'package'
        jdkVersionOption: 11
        publishJUnitResults: true
    - task: Docker@2
      displayName: 'Build Docker image'
      inputs:
        repository: '<my_repo_name>'
        command: 'build'
        Dockerfile: '**/Dockerfile'
        tags: $(Build.BuildId)
    - task: Docker@2
      displayName: 'Push Docker image to Docker hub'
      inputs:
        containerRegistry: 'Dockerhub connection'
        repository: '<my_repo_name>'
        command: 'push'
        Dockerfile: '**/Dockerfile'
        tags: $(Build.BuildId)
- deployment: VMDeploy
  displayName: 'Deployment to VPS'
  pool:
    vmImage: 'Ubuntu-20.04'
  environment:
   name: CDB_VPS
   resourceName: <my_vps_resource_name>
   resourceType: VirtualMachine
  strategy:
    runOnce:
      deploy:
        steps:
        - script: docker pull <my_repo_name>:latest
        - script: docker stop $(docker ps -aq)
        - script: docker run -p 8085:8085 <my_repo_name>:latest

```