Functions/Publish-DatabricksJobsFromConfigToWorkspace.ps1
<#
.SYNOPSIS Deploys DataBricks job(s) from configuration json file(s) to a workspace .DESCRIPTION Deploys DataBricks job(s) from configuration json file(s) to a workspace .PARAMETER config Configuration json file from the environment used to workout whether to deploy a job from a folder or file(s) .PARAMETER localOutputPath The name path of the job configuration files. .EXAMPLE Publish-DatabricksJobsFromConfigToWorkspace -config $config -bearerToken 'dapi1234567890' .NOTES Author: Sabin IO #> Function Publish-DatabricksJobsFromConfigToWorkspace { [cmdletbinding()] Param( [parameter(Mandatory = $true)]$config, [parameter(Mandatory = $true)][string]$localOutputPath ) $localOutputPath = Resolve-Path $localOutputPath try { if (($config.deployJobsByFolder.deploy -eq $true) -and ($config.deployJobsByFileNames.Length -ge 1)) { Write-Error "deployJobsByFolder in config set and deployJobsByFileNames has values. Options are mutually exclusive!" Throw } if (($config.deployJobsByFolder.deploy -eq $true) -and ($config.deployJobsByFileNames.Length -eq 0)) { Write-Verbose "[Deploy] job(s) by folder, Ignoring deployJobsByFileNames" $jobConfigFiles = Get-ChildItem -LiteralPath $localOutputPath -Filter "*.job.config.json" foreach ($jobConfig in $jobConfigFiles) { Write-Host "Publishing Job from $($jobConfig.FullName)" Publish-DatabricksJobToWorkspaceByName -jobConfig $jobConfig.FullName ` -removeSchedule $config.deployJobsByFolder.remove_schedule } } if (($config.deployJobsByFolder.deploy -eq $false) -and ($config.deployJobsByFileNames.Length -ge 1)) { Write-Verbose "[Deploy] job(s) by file(s), Ignoring deployJobsByFolder" foreach ($jobConfig in $config.deployJobsByFileNames) { $jobPath = Join-Path $localOutputPath $jobConfig.job_file_name if (Test-Path $jobPath) { Write-Verbose "Publishing Job from $($jobPath)" Publish-DatabricksJobToWorkspaceByName -jobConfig $jobPath ` -removeSchedule $jobConfig.remove_schedule } else { Write-Error "Path $($jobPath) does not exist. Check file names are correct." } } } } catch { throw $_.Exception } } |