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.
Add a simple console application solution to your repository.
It can contain a simple “hello world” code as shown below.
Now commit this code to the master branch after ignoring all the local files as shown in below.
Make sure to commit and push including the .gitignore file.
Once committed in the solution explorer switch to the folder view.
Right click on the repository root folder and add a new file.
New file would appear in the solution explorer as shown below.
Rename the file to “.vsts-ci.yml”
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
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.
Commit and sync the changes with the master branch.
CI build definition got created and executed.
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.
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:
Post a Comment