Functions/AzDevOps/Set-CdsSolutionsVersionBuild.ps1

<#
    .SYNOPSIS
    Run build action to upgrade solutions versions
#>

function Set-CdsSolutionsVersionBuild {
    [CmdletBinding()]
    param
    (        
        [Parameter(Mandatory = $false)]
        [String]
        $ConnectionString = $env:CONNECTIONSTRING,

        [Parameter(Mandatory = $false)]
        [String]
        $BuildId = $env:BUILD_BUILDID,

        [Parameter(Mandatory = $false)]
        [String]
        $Version = $env:VERSION,

        [Parameter(Mandatory = $false)]
        [String]
        $Solutions = $env:SOLUTIONS
    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); 
    }    
    process {
               
        $cdsClient = New-CdsClient -ConnectionString $ConnectionString;
        
        Write-HostAndLog -Message " - Param : Build ID = $BuildId" -Level INFO;
        Write-HostAndLog -Message " - Param : Solutions = $Solutions" -Level INFO;
        Write-HostAndLog -Message " - Param : Expected version = $Version" -Level INFO;

        $Version = $Version.Replace("X", $buildId);
        $Version = Get-Date -Format $Version;
        Write-HostAndLog -Message "Calculated version => $Version" -Level SUCCESS;

        $solutionList = $Solutions.Split(",");
        $solutionList | ForEach-Object {
            
            $cdsClient | Set-CdsSolutionVersion -SolutionUniqueName $_ -Version $Version;
        }
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Set-CdsSolutionsVersionBuild -Alias *;