Save/SaveAppsInRepository.ps1

function SaveAppsInRepository {
    param (
        [string]$prName,
        [string]$branchName,
        [string]$filterName,
        [string]$pathToPreviousapps,
        [string]$pathToArtifacts
    )

    try {
        az devops configure --defaults organization=$(Build.Repository.Name) project="$(System.TeamProject)" --use-git-aliases true
    }
    catch {
        Write-Error "An error occurred while configuring Azure DevOps: $_"
    }

    try {
        git fetch origin master
        git checkout master
        git checkout -b $branchName
        Get-ChildItem -Path "$pathToPreviousapps" -Filter $filterName | Remove-Item
        Copy-Item -Path $pathToArtifacts -Destination "$pathToPreviousapps" -Recurse
        git add "$pathToPreviousapps"
        git commit -m $prName
        git push origin $branchName
    }
    catch {
        Write-Error "An error occurred while working with Git: $_"
    }

    try {
        $env:AZURE_DEVOPS_EXT_PAT = "$(System.AccessToken)"
        az devops login --organization "$(System.CollectionUri)"
        az repos pr create --repository "$(Build.Repository.Name)" --source-branch $branchName --target-branch master --title $prName --description $prName
    }
    catch {
        Write-Error "An error occurred while creating the pull request: $_"
    }
}