Here is the link to the "home page" for this blog series.

We are going to learn here how to:

We start with Continuous Integration (CI). I am not going in details what is CI, but it is a plenty of blog post about it, just google.

Open our solution we created in the previous blog post here or clone it from my Azure DevOps public project here. If you just started your journey with .NET, I suggest you to use Visual Studio IDE for development, the community edition is free and just good enough, can be downloaded from here.

We are going to add yaml file to the solution.

Create Pipelines folder

Right click on the solution -> Add -> New Solution Folder

New Solution Folder 

Call it Pipelines. I am not sure why, but Visual Studio doesn't create solution folder on the disk, so open File Explorer and create this folder. Right click on the solution and click on Open Folder in File Explorer

Open Folder in File Explorer

Create folder and call it Pipelines

Pipelines

Add YAML file

In the Visual Studio click on File -> New -> File...

New File

Unfortunately, there is no templates for yaml files. I created one issue to the Visual Studio teams but it's got closed.

Anyway, choose just Text File

Text File template

Click on Open.

Click on File -> Save ... As...

Choose Pipelines folder and provide the name azure-pipelines.yml

Click on Save.

Now add file to the solution by right click on the Pipelines folder -> Add -> Existing Item...

Add existing item

Choose the yaml file

And click on Add.

yaml file

Copy and paste the following code

pool:
  vmImage: 'windows-latest'

variables:
  BuildConfiguration: 'Release'
  BuildPlatform: 'Any CPU'
  Solution: 'CreateAndInstallWorkerService.sln'
  WebSiteName: 'TheBestWorkerService'
  ProjectName: 'DemoWorkerService'

steps:
- task: [email protected]

- task: [email protected]
  displayName: 'dotnet restore'
  inputs:
    command: 'restore'
    restoreSolution: '$(Solution)'    

- task: [email protected]
  displayName: 'dotnet build $(BuildConfiguration)'
  inputs:
    command: 'build'
    arguments: '--configuration $(BuildConfiguration)'

- task: [email protected]
  displayName: 'dotnet test $(BuildConfiguration)'
  inputs:
    command: test
    projects: '**/*Tests.csproj'
    arguments: '--configuration $(BuildConfiguration) --collect "Code coverage"'

- task: [email protected]
  displayName: 'dotnet publish $(ProjectName)'
  inputs:
    command: publish
    publishWebProjects: false
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)\$(WebSiteName) $(ProjectName)\$(ProjectName).csproj'
    zipAfterPublish: true

- task: [email protected]
  displayName: 'publish artifacts'

Don't worry, at this point, you have to change only 3 lines of this code.

Ln. 7 is your solution name, mine is CreateAndInstallWorkerService.sln

Ln. 8 is how you want your component should be called in the Services. Service Name

Service Name

Ln. 9 - is the project name

Project name

If you don't interest in learning anything about yaml code just keep reading further but if would like to learn yaml, here is line by line explanation (Coming soon).

Commit and push your code.

Create Pipeline in Azure DevOps

Open Azure DevOps and Navigate to Pipelines

Worker Service public project

Choose Pipelines, before it was called Builds and I think it was better name. It's strange to say Go to Pipelines then Pipelines, but anyway click on

Create Pipeline

Create Pipeline.

Here you have different options you can explorer, but I prefer classic editor

Click on Use the classic editor.

Classic editor

In the classic editor you have full control, at least it feels that way. Choose Azure Repos Git, if you follow along or other Source Control software you prefer, then Repository and branch, here I am just using master and click on Continue.

Select YAML and click on Apply

YAML template

Provide name, I just call it WorkerService, Default agent pool for YAML is Azure Pipelines and file path is Pipelines/azure-pipelines.yml if you followed me or just click on ... and find you file.

Pipelines

Enable Continuous Integration

To set up Continuous Integration meaning trigger build on each push, go to Triggers and check Override the Yaml continuous integration trigger from here

Click on Enable continuous integration and choose the branch. In my case I have only one branch and I am just picking up master branch. Click on Save & queue -> Save

Save

And Save.

Save

Run Pipeline

Now it's time to run the pipeline, go ahead and click on Queue

And Run.

Run pipeline

Now we have to wait for a couple of minutes

Pipeline runnig

After 1 minute and 40 seconds, we got this

Our build went green with one Warning. Pipeline could not find any test and it's Ok because we didn't write any. Look around and check the logs by clicking on Job. There you can find logs from all steps we provided in the yaml file.

Publish Artifacts

The important part here to understand is Published artifacts. If you click on 1 published, you will see the following structure

Artifacts

This is our application archived as zip package, which we are going to copy and host somewhere on the server. This will be next blog post Setting up Deployment for Worker Service.

Here is the link to the "home page" for this blog series.

If you like my post image, you can free download it from here.

Let me know in the comments if you experienced any troubles or if you have any feedbacks. Don't forget to subscribe to get news from Sergey .NET directly to your mailbox.


My Azure DevOps public project Worker Service

Visual Studio Downloads

Add new item - Solution Items - YAML template issue