In the previous section, we examined the Azure DevOps build pipeline and its role in creating a deployable software package (Part 1). In this section, We will delve into the Azure DevOps tasks designed for the release pipeline. These tasks enable you to both upload the deployable software package to a project’s asset library in LCS and subsequently deploy this asset into your LCS environment by setup a release pipeline. Before we proceed, it is essential to ensure that you have completed all the necessary prerequisites as outlined in the first part. You can discover additional information regarding Azure DevOps tasks for LCS by referring to the provided link.

Pre-Requisite:

Before implementing this blog you must have to go through my previous two blogs:

Activate the release system:

To enable the release system, a new application registration for Azure DevOps must be created in your organization’s Azure Active Directory. This will allow your Azure DevOps to connect to the LCS environment. We’ve already created a service account in our first blog, so there’s no need to create one now. You can use your own account’s credentials as admin consent applies to all the accounts in the directory. However, it would be great if you are the administrator in your tenant and use that account to connect with LCS and Azure DevOps. You can find detailed information about registering application in Microsoft Azure Active Directory here too:

Setup A Release pipeline:

Go to Releases in your Azure DevOps project and setup a new release pipeline. I will create a new pipeline that will consist of a single Build artifact and one upload & deployment stages. It is not required to have 1 stage, but it gives me an option to set triggers and approvals for stage individually. For example, you can set up your deployment stage to require approval from a project user before the stage can start. In this scenario, the first stage contains tasks that you will use to upload the build artifact (the software deployable package) to the asset library in your LCS project and then you have to create a second stage that contains tasks that you will use to deploy the asset to selected LCS environment. It’s your own choice which you can adopt according to your own terms & conditions.

 

Start by clicking on the New release pipeline button and select an Empty job template.

Setup a build artifact

Click on Add artifact and provide the requested inputs. Select Build as Source type, provide the name of your project and select your build pipeline as the Source. Use Latest as a Default version if this release should be executed automatically. When finished click Add.

 

To start the release immediately after the build pipeline ends, you must enable the Continuous integration checkbox from the artifact triggers.

 

Setup LCS Upload stage

The LCS upload stage consists of Agent job and 2 tasks: LCS Asset Upload and PowerShell script.

 

Make sure you have selected the same agent pool which we created in part 1 of this blog where we are using this agent to run our build pipeline other than that you can also choose Microsoft Hosted Agent which is provided to run the pipeline but there are some limitation in those agent, Please note that based on your subscription there can be limits for Microsoft-hosted agents which tells you how many agents you can run in parallel, total minutes for job executions per month and maximum execution time for a single job. I believe that by default Microsoft offers 1 parallel job, in total 1800 minutes/month, and a maximum of 60 minutes execution time for a single job.

Agent job configuration is quite intuitive, just ensure that Allow script to access the OAuth token in Additional options is set.

 

Setup Release Script

From Agent job, start by clicking on the Plus button. Search for Powershell Script Task and Add.

 

Here you are getting the required package name and changing it to the required target package name, here is the code of the script:

 

$PackgesFolder=”$(System.DefaultWorkingDirectory)/_Unified Operations platform – Build Main/Packages”

$TargetName=”$(Release.ReleaseName)”

if ((Test-Path -Path $PackgesFolder) -eq $true)

{

Get-ChildItem $PackgesFolder -Filter AXDeployableRuntime*.zip |

Foreach-Object {

Rename-Item -Path $_.FullName -NewName “$TargetName.zip”

}

}

Setup LCS Asset Upload

From Agent job, start by clicking on the Plus button. Search for Dynamics Lifecycle Services (LCS) Asset Upload task and Add. Fill in the required properties for this task. Provide a name for your LCS Asset Upload task. Select an LCS connection from your project’s service connections. Provide the LCS Project Id. You can find it in your LCS project URL e.g.

 

The upload task has an output variable that returns the ID of the asset in the LCS project asset library. Enter a reference name “Upload”. The output variable name must show Upload.FileAssetId.

Setup LCS Asset Deployment

From Agent job, start by clicking on the Plus button. Search for Dynamics Lifecycle Services (LCS) Asset Deployment task.

Fill in the required fields for this task.

Provide a name for your LCS Asset Deployment task. Select an LCS connection from your project’s service connections. Provide LCS Project id and LCS Environment Id. Both Project and Environment Id can be taken from the LCS environment URL e.g.

 

Based on the design of your release pipeline, use $(Upload.FileAssetId) variable as a value for “LCS File Asset Id” field.

Conclusion

Now, you should be able to create a new release on which end the package should be successfully delivered to the selected LCS environment by setup a release pipeline.

 

Hence after successful running of pipeline your package has been uploaded to the LCS Assets

 

 

Thank you for your time reading this, I hope it would be beneficial for you to automate the package uploading & deployment in the Dynamics LCS Environment.

REFERENCE

HAPPY LEARNING!