Define CI&CD in one Azure pipeline

A few weeks ago a client asked me how to create a new pipeline and combine CI&CD in the same pipeline.

I’m not going to explain here why this is not a great idea, and only to define this new pipeline.

So, I’m going to create a new Azure DevOps pipeline for the DEV branch and deploy the application into an Azure web app, and update the database (code first, using Entity Framework Core) into an SQL Azure database.

The first step is to create a trigger for our DEV branch and to define the pipeline variables. For this purpose, we are going to use an Azure web app service created on Windows.


  vmImage: 'windows-latest'

  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'UAT'

Now, it’s time to create the tasks.

- task: NuGetToolInstaller@1

# restore all nuget packages for our solution. In our project we have only one sln file.
- task: NuGetCommand@2
    restoreSolution: '$(solution)'

# build the entire solution
- task: VSBuild@1
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

# publish the project to create a zip file. here I used in our application SlowCheetah in order to have different appsettings configuration files 
- task: DotNetCoreCLI@2
    command: 'publish'
    publishWebProjects: true
    arguments: '-c $(buildConfiguration)'

# create migrations for our database project
- task: efcore-migration-script-generator-task@0
    projectpath: '<EF Core project path>'
    databasecontexts: 'ApplicationDbContext'
    startupprojectpath: '<Default solution project path>'
    targetfolder: '$(System.DefaultWorkingDirectory)/migrations'
    installdependencies: true

# apply migrations to our Azure database
- task: SqlAzureDacpacDeployment@1
    azureSubscription: '<AzureSubscriptionName>'
    AuthenticationType: 'server'
    ServerName: '<Azure ServerName>'
    DatabaseName: '<Azure DatabaseName>'
    SqlUsername: '<Azure SqlUserName>'
    SqlPassword: '<Azure SqlPassword>'
    deployType: 'SqlTask'
    SqlFile: '$(System.DefaultWorkingDirectory)/**/migrations/ApplicationDbContext.sql'
    IpDetectionMethod: 'AutoDetect'

# deploy the files from out publish task to out Azure WebApp service, using WebDeploy method. Also, we can have the option to deploy from a package our application
- task: AzureRmWebAppDeployment@4
    ConnectionType: 'AzureRM'
    azureSubscription: '<AzureSubscriptionName>'
    appType: 'webApp'
    WebAppName: '<Azure WebAppName>'
    UseWebDeploy: true
    DeploymentType: 'webDeploy'
    packageForLinux: '$(System.DefaultWorkingDirectory)/**/*.zip'

Leave a comment

Your email address will not be published. Required fields are marked *