Archive
Azure DevOps (ADO) | Pipelines | Publish and Access Build Artifacts from Staging Directory
In this article, Lets see how to Publish and Access Build Artifacts using ADO Pipeline.
What are Build Artifacts:
- Build artifacts are the files generated by your build.
- In ADO Pipelines, We can use Build.ArtifactStagingDirectory Predefined Variable, on the agent where any artifacts are copied to.
Below are the steps to Publish and Download the Build Artefacts in a ADO Pipeline.
Steps to Publish the Build Artefacts:
- Lets see how to Publish a file to Build Artifacts folder, using following ‘Power Platform Export Solution’ Task.
- In the below Task, I am exporting a Solution from CRM Instance and publishing as $(Build.ArtifactStagingDirectory)\$(SolutionName)_managed.zip by using the ‘Solution Output File’ property.
- In the above the ‘Solution Output File’ property, $(SolutionName) is my custom defined ‘Pipeline Variable’ contains Solution name.
- ‘ALM_Base’ is my Dynamics Instance Solution name.
- And $(Build.ArtifactStagingDirectory) is Predefined Variable.
- Once the pipeline runs successfully, you can download the published artefacts (i.e., Solution folder) as follows.
Steps to Download the Build Artefacts:
- Go to Pipeline Runs and select the last run.
- Click on the below highlighted link.
- Select the folder you want to download.
- We also have an option to commit these files to Git using ‘Command Line Script’ task.
🙂
Azure DevOps – Getting started by committing a C# console project to Repo and set Policies
Those who are hearing ‘Azure DevOps Services’ for the first time, its formerly known as ‘Visual Studio Team Services (VSTS)’.
And Team Foundation Server (TFS) is now called ‘Azure DevOps Server’.
Below table gives the glimpse of how VSTS features represents in Azure DevOps.
To know more about Azure DevOps refer this link
In this article, I am going provide the steps to sign-up for ‘Azure DevOps’ and explain how to on board a C# console project.
Pre-Requisite:
- Microsoft account.
- You can also use your 30 days trail Dynamics Account to login.
- If you’re a Visual Studio subscriber and you get Azure DevOps as a benefit, use the Microsoft account associated with your subscription
Sign up for Azure DevOps:
- Navigate to the VS Portal and click on ‘Get started for free’ as highlighted below
- Log in with your ‘Microsoft Account’
- Once you complete the registration, you will be redirected to Azure DevOps portal.
- A new Organization would have got created by now and to sign in to your organization at any time, go to
https://dev.azure.com/{yourorganization}
.
Create a New Project:
Once you got your Organization ready, next you need to create a new ‘Project’.
- On the ‘Create a Project to get started’ form, provide your project name and set the Visibility.
- Set the Visibility to ‘Private’ if you are working on a customer project which you would not want to expose to Public.
- ‘Public’ visibility is meant for Open Source projects.
- Under ‘Advanced’ tab, I am going with ‘Git’ as my Version Control and ‘Agile’ as Work item process.
- Your ready with Project and we are close to on board our C# console project.
Repos:
After you create a new Organization and Project, you can begin coding with Git using Repos.
- Click on ‘Repos’.
- As a first step in Repos, add ‘README’ or ‘gitignore’, as shown in below.Note that this step is optional but very effective house keeping step.
- README – You can provide description and objective of your project.
- gitignore – Will ignore unwanted files to be added to repos.
- As an example you don’t need components like (Actual nuGet packages, .suo files which comes with VS).
- I’ve added ‘VisualStudio’ option to the ‘gitignore’ which ignores all unwanted VS files.
- Click ‘Initialize’
- Now you would see 2 files added to your Repo.
- As mentioned, ‘.gitignore’ contain unwanted file extensions, auto populated. You can add/remove if you want.
- ‘README.md’, is a Mark Down file which is a combination of Text and HTML tags. Add your project description.
- # Denotes <H1> tag; ## denotes <H2> tag.
Clone the Repo to your computer:
To work with a Git repo, you clone it to your computer. Cloning a repo creates a complete local copy of the repo for you to work with.
In this article, I am going to use ‘Visual Studio’ to Clone the Repo. You can also use ‘Command line’ commands using ‘Command Prompt’
- Click ‘Clone’ and select ‘Clone in Visual Studio’ option under ‘IDE’.
- Now Visual Studio opens up and you might need to provide your Microsoft Account credentials.
- In case if you get ‘Unauthorization’ error, you can connect as below from your VS ‘Team Explorer’.
- Once you complete the clone, the 2 files (i.e., .gitignore, README.md) would synced to your computer folder.
Commit C# Console Project to Repo:
Once you Cloned of your DevOps ‘Project’ to your local computer folder, below are the steps to add a new C# console project to Repo.
- Create a new C# console application project and save at the same folder location where you cloned your Azure Project.
- Now you would see the Console project in your Visual Studio.
- You would notice #5 in the Visual Studio footer, which denotes 5 new files are new and not synced to your Repo.
- You need to commit the files to sync with your Repo.
- Click on #5 icon and provide mandatory ‘Commit comments’ and choose ‘Commit All and Push’ option to commit and upload the C# console project to Repo.
- Now, go to your Azure DevOps portal and you would see your C# console project.
- You can also Edit the class files directly from DevOps portal.
Branch Policies:
As you would have noticed, Visual Studio did not allow me to commit the files until I provide the ‘Comments’. Its a policy implied by default by DevOps.
Lets see how to configure the policies.
- Once you create a new Project, DevOps will create a default ‘master’ branch.
- Refer article for more details on ‘Branch’.
- Under Repos->Branches, select ‘Branch Policies’ from the Branch menu.
- You can configure appropriate policies mainly to improve the code quality.
- Refer link to know more details on Policies.
Grant access on Project to Users:
For every new project you add to DevOps Organization, a new Team gets created with naming convention {Project Name} Team.
- Click on ‘Teams’ tab as shown in screen below and pick your Project team.
- ‘+Add’ to add users
- Refer this link to know more details on managing Teams.
Service Hooks:
- Service hooks let you run tasks on other services when events happen in your Azure DevOps Services projects.
- For example, you can create an entry in Azure Service Bus when there Code commit happens.
- Refer this article for more details on ‘Service Hooks’
In my next article I will share the details on how to implement Build activities using Pipelines
🙂
[Step by Step] Restore a Database from Azure Blob to Azure SQL Server
In one of the requirements, we had to move a Database uploaded to ‘Azure Blob Storage’ to Azure SQL Server.
If you got a question, why we need to move SQL Database file from Azure Blob to Azure SQL Server, like me, below is a sample scenario
- Customer IT team, uploads their Database file to Azure Blob storage every week using AZcopy
- To consume the Data, we either have to restore the Database file to Azure SQL Server or to your local SQL server.
Below are the steps to restore Database file from Azure Blob to Azure SQL Server.
Prerequisites:
- Azure Subscription
- Create a ‘Storage Account’ with ‘Blob’. Refer my previous article for steps to create
- Database file uploaded in Azure Blob Storage
- SQL Server Management Studio (SSMS), as I am going to use this tool in next steps.
Steps to restore Database from Blob to Azure SQL Server:
- Connect to ‘Azure SQL Server’ using SQL Server Management Studio (SSMS)
- Right click on ‘Databases’ and choose ‘Import Data-tier Application…’
- In ‘Import Settings’ tab of the ‘Import Data-tier Application’ window
- Select ‘Import from Windows Azure’
- Click ‘Connect…’
- Provide ‘Azure Storage account’ name
- Account Key
- Click ‘Connect’
- In the next window, pick the Azure Database back up file upload in the Blob and click ‘OK’
- In ‘Database Settings’ tab, provide the ‘New database name’ and click ‘Next’
- That’s it, now the Restore process should start with ‘Progress’ window.
- Give it some time and once the process completed, you will see ‘Success’ Status
🙂
[Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
Connecting to Azure SQL Server from SSIS using ‘OLEDB Connection manager’ is not a straight forward way, if you are to connect using your ‘Azure Account’ credentials.
The only way to connect using ‘Azure Account’ is by using ‘ADO.NET connection’ manager.
But then, how to connect to Azure SQL using OLEDB? Answer is by using ‘SQL User’. And yes, we need to create ‘SQL User’ on the Azure DB which you are connecting to and use the same in SSIS OLEDB.
Below are the steps to create ‘SQL User’ and use that to connect to ‘Azure SQL Server’ from SSIS OLEDB.
Create a ‘SQL Login’ on Azure SQL Server:
- Connect to Azure SQL Server using SQL Server Management Studio (SSMS) using the Azure Account. ‘Azure Account’ must be Administrator to ‘Azure SQL Server’
- Select ‘Master’ Database and open a ‘New Query’ window.
- Note that, ‘SQL Login’ creation query must only run on ‘Master’ database
- Create a ‘Login Account’ using below query. In my query I am creating a Login Account by name ‘MyLogin’
Create a ‘SQL User’ on required Databases:
- Post creation of ‘SQL Login’, now we have to create ‘SQL User’ account against all the Databases, which you want access from SSIS OLEDB.
- From the SSMS -> Object Explorer, select the Database and open a ‘New Query’ window.
- Create a ‘SQL User’ using below query. In my query I am creating a SQL User by name ‘MyUser’
- Add ‘db_datareader’ and ‘db_datawriter’ roles to the ‘MyLogin’ Login Account using below queries.
- Note: You can combine and run ‘Create SQL User’ and ‘Grant Data Reader and Writer Roles’ queries together.
- Also, run ‘Create SQL User’ and ‘Grant Data Reader and Writer Roles’ queries against ‘Master’ Database as well.
- Refer this article for list of ‘Roles’
Connect to Azure SQL from SSIS OLEDB:
As we have ‘SQL User’ created and granted access against the required databases, to connect to Azure SQL from OLEDB.
- Open the ‘OLEDB Connection Manager’
- Set ‘Server name’ to ‘Azure SQL Server’ name
- Set ‘Authentication’ to ‘SQL Server Authentication’
- Set ‘User name’ and ‘Password’ to ‘SQL User’ credentials created in above section
🙂
Dynamics 365 – Using WebHooks to post data from Plugin to Azure Function
In my previous articles, I detailed the steps to create ‘Azure Functions’ and executing D365 SDK messages from ‘Azure Function’.
In this article, lets see how we fulfill Integration requirements using WebHooks model by submitting data to external WebAPIs and Services from D365.
What is a WebHook:
- Webhooks is a lightweight HTTP pattern for connecting Web APIs and services with a publish/subscribe model.
- Webhook senders notify receivers about events by making requests to receiver endpoints with some information about the events.
In this article, I am going to send data from Dynamics Plug-in to Azure Function using WebHooks model. So Plug-in acts as Webhook Sender and Azure Function acts as Receiver.
Below are the steps to create Azure Function and call Function from Plug-in by passing data.
Steps to create Azure Function:
- Refer Create Azure Function article to create Azure Function Apps.
- Create a new ‘Azure Function’ of type ‘Generic webhook’
- Add below logic to Azure function which captures and logs the content posted from Plug-in
Get Azure Function URL:
Copy the ‘Azure Function’ URL along with key which will be used to communicate from Plugin.
- Click on ‘Get function URL’ link and click ‘Copy’ to copy the URL
- URL will have 3 parts
- Endpoint URL
- Code
- ClientId
- We would use only below 2 highlighted values while registering Plug-in.
Registering a WebHook:
- Connect to Dynamics instance from Plug-in Registration tool
- Click on ‘Register New Web Hook’
- In the ‘WebHook Reistration’ page
- Set ‘Endpoint URL’ as the ‘Endpoint URL’ value copied from ‘Azure Function URL’
- Click ‘Add Property’
- Set ‘Key’ as ‘x-functions-key’
- Set ‘Values’ as ‘Code’ copied from ‘Azure Function URL’
Register Plug-in Step on WebHook
- Register a Plug-in step on WebHook assembly
- Create a step on ‘PostAccountCreation’
Test the WebHook:
- Create an Account from D365
- Check the Logs in Azure Function’s ‘Logs’ tab
🙂
Code Snippet – Execute Dynamics 365 WhoAmIRequest in Azure Function
Azure Function is a serverless compute service that enables you to run code on-demand without having to explicitly provision or manage infrastructure.
We can leverage ‘Azure Functions’ in Dynamics 365 to build robust integrations.
Scenario:
Lets take a scenario, where your Customer has a Facebook page and complaints posted on page should get created as ‘Case’ records in your Dynamics application.
In the above scenario,
- Connecting to Facebook and retrieving Posts can be achieved using ‘Logic Apps’ Facebook connector
- Now creating Posts as ‘Cases’ in Dynamics can be done by creating an ‘Azure Function’ with Case create logic and invoke it from ‘Logic App’
In this article, I will walk you through the steps to establish connection to D365 and execute ‘WhoAmIRequest’ from ‘Azure Functions’.
Steps to create Azure Function:
- Refer my previous article for steps to create Azure Function.
Prerequisites to Connect to D365 From Azure Function:
- We would need ‘CRM SDK’ nuget packages in Azure Function to establish connection with D365.
- Below are steps to add nuget packages to ‘Azure Function’
- Connect to ‘Advanced tools(Kudu)‘ from ‘Function Apps -> Platform features‘
- Click on ‘Debug Console -> CMD’
- From the folder explorer, navigate to ‘site -> wwwroot‘ folder
- Open the folder with your Azure Function name
- Since my function name is ‘WhoAmI’ and I got the ‘WhoAmI’ folder under ‘wwwroot‘
- To refer nuget packages, we have to create a new file by name ‘project.json’
- Add below package references
- Save
- Add URL and Credential details of ‘D365’ to ‘Application Settings’ of ‘Azure Function’
- Navigate to ‘Function Apps -> Platform features -> Application Settings’
- Add the URL, UserId, Password details.
Code Snippet:
Once you have the Prerequisites ready, below is the code snippet to execute ‘WhoAmIRequest’
using System.Net;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Crm.Sdk.Messages;
using System.Configuration;public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
try{
log.Info(“Inside Try”);ClientCredentials userCredentials = new ClientCredentials();
var userName = ConfigurationManager.AppSettings[“Crm_UserName”];
var password = ConfigurationManager.AppSettings[“Crm_Password”];
var Crm_UniqueOrgUrl = ConfigurationManager.AppSettings[“Crm_UniqueOrgUrl”];
userCredentials.UserName.UserName = userName;
userCredentials.UserName.Password = password;log.Info(“userName – “+userName);
log.Info(“password – “+password);var service = new OrganizationServiceProxy(new Uri(Crm_UniqueOrgUrl + “/XRMServices/2011/Organization.svc”), null, userCredentials, null);
service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());WhoAmIRequest reqWhoAmI = new WhoAmIRequest();
WhoAmIResponse resp = (WhoAmIResponse)service.Execute(reqWhoAmI);
var buID = resp.OrganizationId.ToString();
var userID = resp.UserId.ToString();log.Info(“Business Unit Id – “+buID);}
catch(Exception ex)
{
log.Info(“Exception – “+ex.Message);
}return req.CreateResponse(HttpStatusCode.OK, “Successfully made call to D365.”);
}
Run and Test the Code:
- Click on ‘Run’ and expand ‘Logs’ section to track the logs.
🙂
Azure – Create and Rename a Function
Other day I was exploring Azure ‘Functions’ and had a tough time to rename the ‘Function’.
Below are the steps to create and rename Azure ‘Function’
What is an Azure Function:
Azure Function is a serverless compute service that enables you to run code on-demand without having to explicitly provision or manage infrastructure.
In simpler words, you can run your code with no Development/Hosting environment. All you need to do is start coding in ‘Azure Function’ editor like you code in Visual Studio, you can even refer external .dlls.
Steps to create Function:
- Connect to your Azure Portal (http://portal.azure.com)
- Create a new “Function App”
- I named it as ‘AzrFunc’
- Under the “Function App”, add a new ‘Function’ of type “Webhook + API”
- Now a ‘Function’ will get created with a default name “HttpTriggerCSharp1”
Steps to rename a Function:
There is no rename option in UI to change the ‘Function’ name and you have to use ‘Console’ from “Platform features -> Development Tools”
- Open the Console
- Type command “ls” which lists out your function name
- Use command “rename” to change the Function name
- Syntax: rename <old_name> <new_name>
- I renamed function to ‘WhoAmI’
- Syntax: rename <old_name> <new_name>
- Restart the ‘Function App’
- Refresh your “Function App”, to see the change
Refer documentation to learn more about ‘Azure Functions’
🙂
Dynamics 365 Data Archival and Retention Tool – MS Labs
Data Archival and Retention is one of the common asks from customers.
Dynamics 365 product offering does not have any native data archival or retention feature, ‘Data Archival and Retention’ solution enables Dynamics 365 users to do archive of required data to COSMOS DB using Azure Services .
Download the solution from App Source and get started !
App Source : Link
User Guide : Link
🙂
Azure Deployment Slots – Deploy and Swap
Assume that you have your live application deployed on Azure running and you must deploy a hot fix.
The option you got is, you might want to take your application down for some time till your hot fix deployed.
How about you deploy the hot fix with no downtime, the answer is Azure “Deployment Slots”.
Create a Deployment Slot:
To use ‘Deployment Slots’, make sure you are running with Standard or Premium Azure Service Plan before adding a slot
- Connect to Azure subscription and open your existing ‘App Service’
- Under ‘DEPLOYMENT’ section, select ‘Deployment Slots’ and click on “Add Slot”
- In the next screen, provide Slot name and choose ‘Configuration Source’. I gave my Slot name ‘Staging’ and in the ‘Configuration Source’:
- If you choose your existing ‘App service’ all the settings including ‘Application Settings/Diagnostic Settings/…’ will be copied to this slot
- Or you can choose ‘Don’t clone configuration….’ Option, if you want your slot to be clean and no carry over settings.
- Click ‘Ok’
- After few seconds, you would get notification that your slot is ready
- Once slot setup completed, your main App name will come as prefix of your slot (Ex: If ABC is my web app; my Slot name is ABC-staging)
Publish Website to Slot:
- Use Visual studio “Publish Web” option
- Select “Microsoft Azure App Service” and choose your main “App Service” and “Deployment Slots -> {Slot}”
- Click “Publish”
- After publishing, your slot would work as any other Web App. You can give the slot URL to test to run BVT
Swap Slot:
- Once you feel your slot is fine and can be promoted as main App
- Click on ‘Swap’
- Select ‘Source’ and ‘Destination’
- Main Web App would always represent as “production”
- “Staging’ is the name of your slot
- Click Ok
- It would take couple of minutes to complete Swap
- Once Swap completes, end users who are accessing would start getting new build with virtually no down time.
Useful points:
- If any errors are identified in production after a slot swap, roll the slots back to their pre-swap states by swapping the same two slots immediately
- You can check your available ‘Deployment Slots’ by opening your Service Plans.
🙂