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:
resources:
- repo: self
queue:
name: Hosted Linux Preview
condition: succeeded()
steps:
- task: Docker@0
displayName: Pull r-test image
inputs:
azureSubscription: '<subscription>'
azureContainerRegistry: '<registry>'
action: 'Run a Docker command'
customCommand: 'pull <registry>/r-test:3.4.4'
- task: Docker@0
displayName: Build image
inputs:
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
inputs:
testResultsFiles: 'test-results.xml'
searchFolder: '$(Build.SourcesDirectory)'
- task: PublishCodeCoverageResults@1
displayName: Publish code coverage
inputs:
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 .
.