web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Get next version using...
Power Apps
Unanswered

Get next version using Power Platform Build Tools in DevOps Pipelines

(0) ShareShare
ReportReport
Posted on by 9

Hi everyone,

In order to export automatically solutions from Dev environment to QA/Prod environment we need to retrieve automatically what is the next version without the necessity to calculate it.

We want to retrieve the whole version number without the necessity of calculate this number as usually has been done before.
We don't want to calculate something like this: 1.0.0$(Build.BuildNumber)
We want to directly generate or get the version number with other variable like: $(System.NextVersionNumber), this should be something like 1.0.02, etc

Is there any system variable that we can use?
When we export the solution manually, it usually suggest the next version number, this is what I'd like to implement into Azure DevOps Pipelines - Microsoft Power Platform Build Tools

RodrigoQuintana_0-1694489341944.png

 

I have the same question (0)
  • Parvez Ghumra Profile Picture
    1,579 Moderator on at

    @RodrigoQuintana If I understand you correctly, I think you're trying to set the solution version dynamically based on the existing version number of the solution. Like an auto-incrementing logic whenever a change is made/attempted to be committed? Please correct me if I'm wrong.

     

    I think you will have to write your custom custom logic to retrieve the current version number of the target solution, and hold this value in memory before deriving the new version number from it and passing this value as an input parameter into the Set Solution Version number task

     

    I'm using Power Platform GitHub Action on my current project and I have had to do the same using a PowerShell script based on the branch being worked on

  • RodrigoQuintana Profile Picture
    9 on at

    Exactly @parvezghumra ,

    That's what I'd like to achieve, do you have any reference link to example I can based on?

    Thank u for your help, I appreciate it.

  • Parvez Ghumra Profile Picture
    1,579 Moderator on at

    @RodrigoQuintana The first thing you need to do is to establish your solution versioning convention. This will be unique to your circumstances (as an example you can base in on calendar or your sprint cycles if you like), but it will also need to consider how it aligns with your branching strategy. But as an example, here's the convention that I've implemented on a few projects and it has worked well so far:

     

    Major portion of solution version number is reserved to hold the year in which the change is made and committed. And it is only incremented for changes made on the main branch. It does not change if the change is committed on the hotfix branch

    Minor portion of solution version number is reserved to hold the numeric representation of the calendar month in which the change is made and committed. And it is only incremented for changes made on the main branch. It does not change if the change is committed on the hotfix branch

    Build portion of solution version number holds the auto-incremented value for every change made and committed on the main branch. It does not change if the change is committed on the hotfix branch

    Version portion solution version number holds the auto-incremented value for every change made and committed on the hotfix branch. For changes on the main branch is is always set to 0

     

    Here's what my PowerShell script looks like:

     

    param(
     $serverURL,
     $clientId,
     $secret,
     $solutionUniqueName,
     [bool]$incrementBuild,
     [bool]$incrementRevision
    )
    $ErrorActionPreference = 'Stop'
    Set-PSRepository PSGallery -InstallationPolicy Trusted
    Install-Module Microsoft.Xrm.Data.PowerShell -Scope CurrentUser -Force
    Import-Module Microsoft.Xrm.Data.Powershell -Scope Global -Force 
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    Write-Host "Connecting to CRM"
    Connect-CrmOnline -ServerUrl $serverURL -OAuthClientId $clientId -ClientSecret $secret
    Write-Host "Successfully connected to CRM"
    Write-Host "Retrieving current version of" $solutionUniqueName "solution"
    $results = Get-CrmRecords -EntityLogicalName "solution" -FilterAttribute "uniquename" -FilterOperator "eq" -FilterValue $solutionUniqueName -Fields solutionid,uniquename,friendlyname, version 
    $solutionRecord = $results.CrmRecords[0]
    $currentVersion = $solutionRecord.version
    
    Write-Host "Current Version: " $currentVersion
    
    $versionComponents = $currentVersion.Split(".")
    Write-Host "Major: " $versionComponents[0]
    Write-Host "Minor: " $versionComponents[1]
    Write-Host "Build: " $versionComponents[2]
    Write-Host "Revision: " $versionComponents[3]
    
    $newMajor = $versionComponents[0]
    $newMinor = $versionComponents[1]
    $newBuild = [int]$versionComponents[2]
    $newRevision = [int]$versionComponents[3]
    
    if ($incrementBuild -eq $true){
     $currentYear = Get-Date -Format "yyyy"
     $currentMonth = Get-Date -Format "MM"
     if (($currentYear -ne $newMajor) -or ($currentMonth -ne $newMinor))
     {
     $newBuild = 0
     }
     else{
     $newBuild++
     }
     $newMajor = $currentYear
     $newMinor = $currentMonth
     $newRevision = 0
    }
    else {
     if ($incrementRevision -eq $true){
     $newRevision++
     }
    }
    $fullVersion = $newMajor + "." + $newMinor + "." + [string]$newBuild + "." + [string]$newRevision
    
    Write-Host "New Major: " $newMajor
    Write-Host "New Minor: " $newMinor
    Write-Host "New Build: " ([string]$newBuild)
    Write-Host "New Revision: " ([string]$newRevision)
    Write-Host "New Version: " $fullVersion
    
    $solutionRecord.version = $fullVersion
    Write-Host "Setting version of" $solutionUniqueName "solution to" $fullVersion
    Set-CrmRecord -CrmRecord $solutionRecord
    Write-Host "Success"
    Write-Output "Solution_Version=$fullVersion" >> $GITHUB_ENV

     

    And here's how I call it from my GitHub Action workflow before performing the solution export, unpack and commit to source control:

     

     - name: Sync Solution Version for Main Branch
     id: sync-solution-for-main-branch
     if: github.ref == 'refs/heads/main'
     shell: powershell
     run: |
     .\Build\Scripts\SyncSolutionVersion.ps1 -serverURL ${{vars.URL}} -clientId ${{env.CLIENT_ID}} -secret ${{env.SECRET}} -solutionUniqueName ${{ github.event.inputs.solution_name }} -incrementBuild $true -incrementRevision $false
     - name: Sync Solution Version for Hotfix Branch
     id: sync-solution-for-hotfix-branch
     if: github.ref == 'refs/heads/hotfix'
     shell: powershell
     run: |
     .\Build\Scripts\SyncSolutionVersion.ps1 -serverURL ${{vars.URL}} -clientId ${{env.CLIENT_ID}} -secret ${{env.SECRET}} -solutionUniqueName ${{ github.event.inputs.solution_name }} -incrementBuild $false -incrementRevision $true

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard