Learn how to deploy plugins with Azure DevOps Pipeline

Last week, we already learn how to set up Azure DevOps Pipeline for Web Resources. And this week, we will learn how to set up the pipeline, but for the Plugin (backend customization). And the interesting part, we also will implement the Plugin Package (or plugin-dependent assembly). What we will accomplish will be like the below diagram:

diagram update plugin to dev environment

For the plugin project, I prepared the below project:

Plugin project

From the image above, I created a plugin project where I want to update Contact.FirstName, Contact.LastName, and Contact.JobTitle when on create. For the structure, I always love to separate the business and the plugin classes. After setting this up, I register the plugin package and create the plugin step like the below screenshot:

Plugin step

So the idea with the pipeline that we want to setup are:

  • The plugin steps will follow the value in the DEV CRM environment
  • The plugin assembly must be taken from the code that is being stored in the repo (take the latest state)

Once we have done this, we must know the Plugin Package Id that we need to update. For this part, I’m using SQL 4 CDS by Mark Carrington and executing the below query:

Query the plugin package id

Once you know the plugin assembly that you are creating in the DEV Environment, you need to store the pluginpackageid for the next step.

Azure Pipeline

The full azure-pipeline.yml for the demo will be:

trigger: 
- master

pool:
  vmImage: 'windows-latest'

stages:
  - stage: 
    jobs: 
    - job: BuildPlugins
      steps:
      - task: NuGetToolInstaller@1
        inputs:
          versionSpec: 
          checkLatest: true
      - task: NuGetCommand@2
        inputs:
          command: 'restore'
          restoreSolution: '**/*.sln'
          feedsToUse: 'select'
      - task: VSBuild@1
        inputs:
          solution: '**\*.sln'
          clean: true
      - task: CopyFiles@2
        inputs:
          sourceFolder: 'Src/Backend'
          contents: '**\bin\**'
          flattenFolders: true
          targetFolder: $(Build.ArtifactStagingDirectory)/Plugins
        displayName: 'Copy Plugin Packages' 
      - task: PublishPipelineArtifact@1
        inputs:
          targetPath: '$(Build.ArtifactStagingDirectory)'
          artifactName: DataversePlugins
        displayName: 'Publish Dataverse Plugins artifact'
      - task: NuGetCommand@2
        displayName: 'Install PAC'
        inputs:
          command: 'custom'
          arguments: 'install Microsoft.PowerApps.CLI -OutputDirectory pac'
      - task: PowerShell@2
        inputs:
          targetType: 'inline'
          script: |
            $pacNugetFolder = Get-ChildItem "pac" | Where-Object {$_.Name -match "Microsoft.PowerApps.CLI."}
            $pacPath = $pacNugetFolder.FullName + "\tools"
            echo "##vso[task.setvariable variable=pacPath]$pacPath"
        displayName: 'Set PAC path'
      - task: PowerShell@2
        displayName: 'Create Auth'
        inputs:
          targetType: 'inline'
          script: |
            $env:PATH = $env:PATH + ";" + "$(pacPath)"
            pac auth create -u $(devUrl) -n Dev -un $(devUsername) -p $(devPassword)
      - task: PowerShell@2
        displayName: 'Push Plugin Package'
        inputs:
          targetType: 'inline'
          script: |
            $env:PATH = $env:PATH + ";" + "$(pacPath)"
            pac plugin push -id {yourpluginpackageid} -pf $(Build.ArtifactStagingDirectory)\Plugins\Plugins.1.0.0.nupkg

Before we go deep step by step, on the above yml, you need to provide these variables on your pipeline:

Pipeline variables

The explanation of the steps needed are:

  1. NuGetToolInstaller@1: Install the NuGet tool installer
  2. NuGetCommand@2: Restore the NuGet packages of the solution
  3. VSBuild@1: Build the solution and the plugin project will generate the .nupkg file on the bin/Debug folder.
  4. Copy Plugin Packages (CopyFiles@2): Copy the **/bin/** files to the Artifact/Plugins folder
  5. Publish Dataverse Plugins artifact (PublishPipelineArtifact@1): Publish the artifact files so we can use the files needed.
  6. Install PAC (NuGetCommand@2): Once again, Benedikt Bergmann teaches me how to use PowerPlatform CLI tools in the Azure DevOps pipeline in this blog post. The idea is because there is no action that we can use directly, we install Microsoft Power Platform CLI tools in the pipeline so we can make all the commands necessary to push the plugin package to the DEV Environment.
  7. Create Auth (PowerShell@2): Using the Powershell command, we can run “pac auth create -u $(devUrl) -n Dev -un $(devUsername) -p $(devPassword)” to create the connection to the DEV environment
  8. Push Plugin Package (PowerShell@2): the last step is to run “pac plugin push -id {yourpluginpackageid} -pf $(Build.ArtifactStagingDirectory)\Plugins\Plugins.1.0.0.nupkg“. You need to input all the plugin assemblies one by one with the correct file path and the correct plugin package id.

Once you have done the above, here is the screenshot of the demo:

Happy DevOps-ing!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.