The challenge
I recently got a requirement from a Microsoft customer engagement (Dynamics 365) client to manage publishing (export/import) of solutions among diffrent environments (from Dev to Test, QA and PROD). The client wanted to restirct use of PowerApps admin center and CRM for solution publishing. The need arised becuase the client was enterprise and CRM was intergral part for their sales and services operations and they needed to track what has been implemented, who implemented, changes and fixes with existing and new solutions. On top if it, they wanted a new application for solution publishing like, with a single click they are able to publish it to other CRM environments. After some discussions they wanted the application to be more interactive and responsive so that they can see the publishing results and be notified, applicaiton can be accesible from anywhere, any device, be able to share securely with other departments in the organization (Office Groups).
The Solution
No question, PowerApps was the way to go for application as per their requirment, but next question was how we going to automate crm solution deployment among crm instances. Well there are others solution available but thanks to Power Platform Build Tools for DevOps which solves our automatic solution deployment with source control. They are also helpful for versioning and deploying PCF controls for future. After quick demo of Build Tools to client we agree on making and defining new Build and release pipelines for CRM Test, QA and PROD instances with funtionality of Continuous deployment trigger (means whenver we have new build aritcraft a release pipeline will trigger and deploy solution except for PROD which needs approval first).
But next challange was how we going to queue the builds for CRM deloyments, here Azure DevOps API comes to rescue us, which come as .Net Client Libraries and Rest API flavors. Just to save time (demo) I go with .Net client libraries with PAT authentication method but you can read this document for token authentication. PAT is also helpful in restircting access to DevOPs Project. Please note in appsetting.json the CollUrl refers to url of your devops organization (https://dev.azure.com/{yourorganization}).
But how do we use Azure DevOps API directly into our application that was a challange and what if we want to use this Azure DevOps API in our existing application in way we want, how we can do that. So I decided to wrapp the DevOps API into our own ASP.Net Core 3.1 WebAPI and later expose this as Custom Connector into organiation, so our PowerApp can use it. Why we build our own WebAPI becuase we have some internal operations to perform along with solution deployment for example, notifications in Jira or DevOPs workitems linked to story or parent workitems and attachemnts etc.
Here is the plain source code of WebAPI (controllers for Build Operations and WorkItems).
Please note here, if I just barely need to call pipeline from any application, then that is possible through some webhook like Azure function or Power automate but as I mentioned we want our application to be more interactive and responsive that is why it is exposed as Rest API. Here is simple screenshot of our PowerApps Custom Connector based on our WebAPI controllers.
The Application (PowerApp):
Enough talking, time to show what we have done so far. Here I will just show screen shots of PowerApp with sequence number and WebAPI operation behind. Please note the screen shot contains dummy data just for understanding what happenings.
Now we have DevOps project and pipelines selected, now it is time to select a solution and deploy it to one or more CRM instances.
Now next screen will show the status and logs of executing pipeline.Please notethe screen below shows end result but in reality the result will be displayed as long as the pipeline executes. For example the status changes from Queued -> InProgess -> Completed/Failed. I use timer control to fetch status as the pipeline executes. I recommend use of PowerAppsConcurrentfunction if you want stablity in http requests and then loading result in controls in a sequence.
Here is link for very basic Azure Pipelines for Dynamic365. YAML. Just to give you an idea to start and you can customize according to your needs.
Finally my goal for this post is just to share my experience and sure, there are endless possibilities with DevOps API as you queue any type of pipelines for open source frameworks and technologies (non microsoft) not even from jsut from PowerApp.
Feel free to contact me if you need any informaiton about technology we use so far and feel free to use source code of WebAPI on github. even you can extend it to your needs, there are lot of functions I have not mentioned here.
Happy CRMING and DevOps 😊