Tuesday 21 November 2017

Build Definition as Code with YAML Builds

Build configuration as code and store it in version control was a request from some time back. It is great to have your build definition as code alongside your application source code. Microsoft has now released preview of YAML builds for this purpose to VSTS. Even though as of now it is limited to use with VSTS GIt and GitHub, version control (TFSVC not supported) to create CI builds, it is just the beginning of a new way to think about defining CI, CD pipelines and it will evolve into much greater levels in the future. Let’s get a basic YAML build done to understand what it is.


First create a team project in VSTS with GIt repository. Then clone it to your machine.image

Add a simple console application solution to your repository.image

It can contain a simple “hello world” code as shown below.image

Now commit this code to the master branch after ignoring all the local files as shown in below.image

image

Make sure to commit and push including the .gitignore file.image

Once committed in the solution explorer switch to the folder view.image

Right click on the repository root folder and add a new file.image

New file would appear in the solution explorer as shown below.image

Rename the file to “.vsts-ci.ymlimage

Add below content to the file. The below YAML script perform two steps dotnet restore and dotnet build.

steps:

- task: dotNetCoreCLI@1
   inputs:
     command: restore
     projects: "**/*.csproj"
     displayName: dotnet restore

- task: dotNetCoreCLI@1
   inputs:
     command: build
     projects: "**/*.csproj"
     arguments: --configuration release
     displayName: dotnet build

image

Before committing and pushing this file to master branch check the build definitions of the team project. There is no build definition in the team project.image

Commit and sync the changes with the master branch.image


File just added.image

CI build definition got created and executed.image

image

You can make changes to you the YAML file to change the build definition behavior. Generated build definition does not have detailed steps to edit in web interface instead it has the path to the YAML file.image

It is still limited functionality and you can find a comparison of YAML builds with web interface builds here. It is still at basic level but looks promising and will evolve into more capable CI, CD pipelines as code, which can be version controlled with the application source code.

No comments:

Popular Posts