Create new release pipeline

Create new release pipeline #

New pipeline #

Create new release pipeline

Select empty job #

Select empty job

Setup release Pipeline name and Stage name #

Stage name

Add artifact #

Add artifact

  • (1) - Click on Add an artifact
  • (2) - Select Build
  • (3) - Select project name
  • (4) - select build pipeline name
  • (5) - Latest
  • (6) - It fill by default

Continuous deployment trigger #

Select it if you want to run release automatically after Build pipeline finish work Continuous deployment trigger

Job agent tasks #

Select tasks Continuous deployment trigger

Agent job property #

Agent job property

  1. Display name = Agent job
  2. Agent pool = Azure Pipelines and Agent Specification = windows-latest, Demands\Name = azureps, condition = exists. If we want to run pipe line on client managed VM - select Agent pool = Default
  3. Parallelism = None
  4. Timeout = 720
  5. Allow scripts to access the OAuth token = True
  6. Run this job = Only when all previous jobs have succeeded

Press “+” button Add tasks

Read release note file #

Add Powershell script with propertyes Read release note file

  1. Display name = Read release note file
  2. Type\Inline =
$filePath = "$(System.DefaultWorkingDirectory)/_D365FO-Main-DEV/Packages/ReleaseNote_$(Build.BuildNumber).txt"
$text = Get-Content -Encoding UTF8 $filePath -Raw

$newlineDelimited = $text -replace '\r\n', "\n"

echo $newlineDelimited
echo "##vso[task.setvariable variable=ReleaseNote;]$newlineDelimited"

value $filePath = "$(System.DefaultWorkingDirectory)/_D365FO-Main-DEV can be taken from Agent Job - Artifact download section

  1. Control Options\Enabled = True

Cut release note to 1000 symbols #

Add Powershell script with propertyes Get first 1000 symbols of release note

  1. Display name = Get first 1000 symbols of release note
  2. Type\Inline =
$note = "$(ReleaseNote)"
if ($note.length -gt 1000) {
$result = $note.SubString(0,1000)
echo "##vso[task.setvariable variable=ReleaseNote;]$result"
}

  1. Control Options\Enabled = True

Install MSAL.PS to enable authentication #

Add Install MSAL.PS to enable authentication script with propertyes. This step necessary if we want to upload package to the LCS and deploy it to target environment Install MSAL.PS to enable authentication

  1. Display name = Install MSAL.PS to enable authentication
  2. Control Options\Enabled = True

Install MSAL.PS to enable authentication #

Add Install MSAL.PS to enable authentication script with propertyes. This step necessary if we want to upload package to the LCS and deploy it to target environment Install MSAL.PS to enable authentication

  1. Display name = Install MSAL.PS to enable authentication
  2. Control Options\Enabled = True

LCS Upload to Asset library #

Add Dynamics Lifecycle Services (LCS) Asset Upload script with propertyes. LCS Upload  to Asset library

  1. Display name = LCS Upload to Asset library
  2. LCS Connection = LCS deployment connection. Please find how to create new connection here
  3. LCS Project Id = Project ID in LCS.
  4. Type of asset = Software Deployable Package
  5. File to upload = $(System.DefaultWorkingDirectory)/_D365FO-Main-DEV/Packages/AXDeployableRuntime_$(Build.BuildNumber).zip
  6. LCS Asset Name = XXX_$(Build.BuildNumber), where XXX = TEST/UAT/PROD ….
  7. LCS Asset Description = $(ReleaseNote)
  8. Wait for Validation = True
  9. Control Options\Enabled = True
  10. Reference name = Upload

Deploy to environment #

This step can be split to separate stage with approvement before deploy to target env. In this case we should transfer few variables to the new stage. Add Dynamics Lifecycle Services (LCS) Asset Deployment script with propertyes. Deploy to environment

  1. Display name = Deploy to environment
  2. LCS Connection = LCS deployment connection. Please find how to create new connection here
  3. LCS Project Id = Project ID in LCS.
  4. LCS Environment Id = environment Id from LCS
  5. LCS File Asset Id = $(Upload.FileAssetId). This is reference name from previous step
  6. Type of asset = Software Deployable Package
  7. Name for the update = $(Release.ReleaseName)
  8. Wait for Validation = FALSE (this step is going about 1h-4h)
  9. Control Options\Enabled = True

Approval process and split upload to LCS and deploy to target env #

Upload and deploy can be split for many different reasons. It can looks like: Split upload and deploy

Where 1,2,3 - Points where we can setup different approval logic.

4 - Upload to LCS, 5,6 - deploy to target environment.

In this case Upload stage has step to populate variables for next steps. Add variable to Pipeline variables like LCSAsset Add scope variable

And setup Inline powershell step Upload save step

  1. Powerhell script type Run Inline Powershell
  2. Display name = Inline Powershell
  3. Script to run =
# Populate & store value to update pipeline
$assetId= "$(Release.FileAssetId)"
Write-Output ('##vso[task.setvariable variable=localAsset]{0}' -f $assetId)
 
#region variables
$ReleaseVariableName = 'LCSAsset'
$releaseurl = ('{0}{1}/_apis/release/releases/{2}?api-version=5.0' -f $($env:SYSTEM_TEAMFOUNDATIONSERVERURI), $($env:SYSTEM_TEAMPROJECTID), $($env:RELEASE_RELEASEID)  )
#endregion
 
#region Get Release Definition
Write-Host "URL: $releaseurl"
$Release = Invoke-RestMethod -Uri $releaseurl -Headers @{
    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}

And we can use variable LCSAsset on the next stage - step Dynamics Lifecycle Services (LCS) Asset Deployment, property LCS File Asset Id = $(LCSAsset)

comments powered by Disqus