Module/DevOps/New-BCSPipeline.ps1

<#
.SYNOPSIS
  Update Azure Pipeline files from Template Project
 
.DESCRIPTION
  Update current.yml and build-settings.json from the project template repository and copy the files to your local project folder.
 
.PARAMETER PipelineFilesFolder
  Local folder where to your AL project
  
.PARAMETER Project
  DevOps project where the template repository exists, default is BrightCom Solutions
  
.PARAMETER TemplateRepository
  Name of the template project repository, default is BCS AL Project Template
  
.PARAMETER PipelineFilesSubFolder
  Path to local pipeline files, default is .azureDevOps
 
.PARAMETER PipelineFileName
  Name of the pipeline yaml file, default is current.yml
 
.PARAMETER PipelineBuildSettingsFileName
  Name of the pipeline build-settings file, default is build-settings.json
 
.PARAMETER ContainerName
  Name of the container that is created when the pipeline runs.
 
.PARAMETER DeployToTenant
  Tenant for where artifacts is to be deployed by the pipeline, must be a QA tenant.
 
.EXAMPLE
  Update-BCSDevPipelineFiles -PipelineFilesFolder C:\Projects\myAlProject -ContainerName myAlProject -DeployToTenant desenioqa
.NOTES
    Author: Mathias Stjernfelt
    Website: http://www.brightcom.se
#>


function New-BCSPipeline {
  [CmdletBinding(SupportsShouldProcess)]
  Param (
    [Parameter(Mandatory = $true)]
    [string]$organisation,
    [Parameter(Mandatory = $true)]
    [string]$projectName,
    [Parameter(Mandatory = $true)]
    [string]$repositoryName,
    [Parameter(Mandatory = $true)]
    [string]$pipelineFolderName,
    [Parameter(Mandatory = $true)]
    [ValidateSet('Deployment', 'Release')]
    [string] $pipelineType

  )

  try {
    $fullOrgUrl = "https://dev.azure.com/$organisation";

    switch ($pipelineType) {
      "Deployment" { $ymlPath = ".azureDevOps\pte-qa-current.yml" }
      "Release" { $ymlPath = ".azureDevOps\pte-prod-release.yml" }
    }

    #Setups Pipelines
    if (-not [string]::IsNullOrEmpty($pipelineFolderName)) {
      $f = az pipelines folder list --path $pipelineFolderName --org $fullOrgUrl --project $projectName

      if ($f -eq '[]') {
        if ($PSCmdlet.ShouldProcess("")) {
          az pipelines folder create --path $projectName --project $projectName --org $fullOrgUrl  | convertfrom-json
          az pipelines create --name $CIPipelineName --folder $pipelineFolderName --project $projectName --repository $repositoryName --repository-type tfsgit --branch main --org $fullOrgUrl --yml-path $ymlPath | convertfrom-json
        }
      }
    }
    else {
      if ($PSCmdlet.ShouldProcess("")) {
        az pipelines create --name $CIPipelineName --project $projectName --repository $repositoryName --repository-type tfsgit --branch main --org $fullOrgUrl --yml-path $ymlPath | convertfrom-json    
      }
    }
  }
  catch {
    throw "An error occured: $_.Exception";
  }
}

Export-ModuleMember -Function Copy-BCSRepository