CI/CD
Solution Check-in
The pipeline is responsible for extracting the unmanaged and managed solution from the development environment. The solution gets unpacked into the DevOps repository and checked in. The release pipelines are using the checked in version of the solution.
The {{SOLUTION_NAME}}
and {{SERVICE_PRINCIPAL}}
variables should be upodated.
trigger: none
variables:
solutionName: {{SOLUTION_NAME}}
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
persistCredentials: true
- task: PowerPlatformToolInstaller@2
displayName: 'Install Power Platform Toolings'
inputs:
DefaultVersion: true
- task: PowerPlatformExportSolution@2
displayName: 'Export Unmanaged Solution: $(solutionName)'
inputs:
authenticationType: 'PowerPlatformSPN'
PowerPlatformSPN: '{{SERVICE_PRINCIPAL}}'
SolutionName: '$(solutionName)'
SolutionOutputFile: '$(build.binariesdirectory)/$(solutionName)_unmanaged.zip'
AsyncOperation: true
MaxAsyncWaitTime: '60'
- task: PowerPlatformUnpackSolution@2
displayName: 'Unpack Unmanaged Solution: $(solutionName)'
inputs:
SolutionInputFile: '$(build.binariesdirectory)/$(solutionName)_unmanaged.zip'
SolutionTargetFolder: 'solution/$(solutionName)/Unmanaged'
- task: PowerPlatformExportSolution@2
displayName: 'Export Managed Solution: $(solutionName)'
inputs:
authenticationType: 'PowerPlatformSPN'
PowerPlatformSPN: '{{SERVICE_PRINCIPAL}}'
SolutionName: '$(solutionName)'
SolutionOutputFile: '$(build.binariesdirectory)/$(solutionName)_managed.zip'
Managed: true
AsyncOperation: true
MaxAsyncWaitTime: '60'
- task: PowerPlatformUnpackSolution@2
displayName: 'Unpack Managed Solution: $(solutionName)'
inputs:
SolutionInputFile: '$(build.binariesdirectory)/$(solutionName)_managed.zip'
SolutionTargetFolder: 'solution/$(solutionName)/Managed'
SolutionType: 'Managed'
- task: Bash@3
displayName: 'Commit unpacked solution files'
inputs:
targetType: 'inline'
script: |
git config --global user.email "auto-commit@osb.group"
git config --global user.name "Auto Commit"
git -C "$(System.DefaultWorkingDirectory)/solution/$(solutionName)" status
git -C "$(System.DefaultWorkingDirectory)/solution/$(solutionName)" checkout -b main
git -C "$(System.DefaultWorkingDirectory)/solution/$(solutionName)" status
git -C "$(System.DefaultWorkingDirectory)/solution/$(solutionName)" add .
git -C "$(System.DefaultWorkingDirectory)/solution/$(solutionName)" status
git -C "$(System.DefaultWorkingDirectory)/solution/$(solutionName)" commit -a -m "DevOps auto commit"
git -C "$(System.DefaultWorkingDirectory)/solution/$(solutionName)" push origin main
Package & Deploy
After the solution has been checked in, a package can be created using the pipeline below. This package can then be deployed to the TEST, PROD, etc environments as managed solution.
The {{SOLUTION_NAME}}
and {{SERVICE_PRINCIPAL}}
variables should be upodated. Environments should be created with the name stored in the {{ENVIRONMENT_NAME}}
variable.
Usage of environments in connection with the deployments can make it easier to see what version is deployed to each environment.
trigger: none
pool:
vmImage: windows-latest
variables:
solutionName: {{SOLUTION_NAME}}
rev: $[counter('', 1000)]
stages:
- stage: create_artifacts
displayName: Create Artifacts
jobs:
- job: Build
steps:
- task: PowerPlatformToolInstaller@2
displayName: Install Power Platform Toolings
inputs:
DefaultVersion: true
- task: PowerShell@2
displayName: 'Set Solution Version'
inputs:
targetType: 'inline'
script: |
$solutionXmlPath = "solution/$(solutionName)/Managed/Other/Solution.xml"
[xml]$xml = Get-Content $solutionXmlPath
[version]$version = $xml["ImportExportXml"]["SolutionManifest"]["Version"].InnerText
[version]$newVersion = [Version]::new($version.Major, $version.Minor, $version.Build, $(rev))
echo "Exported Version:" $version
echo "New Version:" $newVersion
$xml["ImportExportXml"]["SolutionManifest"]["Version"].InnerText = $newVersion.ToString()
$xml.Save($solutionXmlPath);
- task: PowerPlatformPackSolution@2
displayName: 'Pack Solution $(solutionName)'
inputs:
SolutionSourceFolder: 'solution/$(solutionName)/Managed'
SolutionOutputFile: '$(Build.ArtifactStagingDirectory)/$(solutionName)_managed.zip'
SolutionType: 'Managed'
- task: PublishBuildArtifacts@1
displayName: Publish Artifacts to drop
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: deploy_to_test_env
displayName: 'Deploy to TEST'
dependsOn: create_artifacts
jobs:
- deployment: 'deployment_test_env'
displayName: 'Deploy'
environment: '{{ENVIRONMENT_NAME}}'
strategy:
runOnce:
deploy:
steps:
- task: PowerPlatformToolInstaller@2
displayName: Install Power Platform Toolings
inputs:
DefaultVersion: true
- task: PowerPlatformImportSolution@2
inputs:
authenticationType: 'PowerPlatformSPN'
PowerPlatformSPN: '{{SERVICE_PRINCIPAL}}'
SolutionInputFile: '$(Pipeline.Workspace)/drop/$(solutionName)_managed.zip'
AsyncOperation: true
MaxAsyncWaitTime: '60'
HoldingSolution: true
ConvertToManaged: true
- task: PowerPlatformApplySolutionUpgrade@2
inputs:
authenticationType: 'PowerPlatformSPN'
PowerPlatformSPN: '{{SERVICE_PRINCIPAL}}'
SolutionName: '$(solutionName)'
AsyncOperation: true
MaxAsyncWaitTime: '60'