Robert's Data Science Blog

YAML Builds in VSTS

The point-and-click configuration of builds in VSTS is easy to use, but it also has a downside: The build itself is not version controlled.

Having used GitHub to host code and Travis CI for testing, this is a feature I really miss.

But now there is a preview feature on VSTS called YAML builds. As the name suggests the build pipeline is specified in a YAML file.

There is even an official example for testing Python using a hosted (Linux) solution. I had not found that example when I wrote my post on testing Python

As an example consider the YAML file for the pipline I made for testing R code:

- repo: self
  name: Hosted Linux Preview
  condition: succeeded()
- task: Docker@0
  displayName: Pull r-test image
    azureSubscription: '<subscription>'
    azureContainerRegistry: '<registry>'
    action: 'Run a Docker command'
    customCommand: 'pull <registry>/r-test:3.4.4'

- task: Docker@0
  displayName: Build image
    dockerFile: Dockerfile
    imageName: 'test:latest'

- bash: |
   docker run test:latest
   CONTAINERID=`docker ps -alq`
   docker container cp $CONTAINERID:/tmp/VSTS/test-results.xml .
   docker container cp $CONTAINERID:/tmp/VSTS/coverage.xml .
  displayName: Bash Script

- task: PublishTestResults@2
  displayName: Publish Test Results
    testResultsFiles: 'test-results.xml'
    searchFolder: '$(Build.SourcesDirectory)'

- task: PublishCodeCoverageResults@1
  displayName: Publish code coverage
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Build.SourcesDirectory)/coverage.xml'

This file is saved as .vsts-ci.yml in the root of the repository.

The second task where the custom Docker image is build could also be moved into the Bash script as docker build --tag test:latest ..