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 bearerToken Your Databricks Bearer token to authenticate to your workspace (see User Settings in Datatbricks WebUI) .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]$bearerToken, [parameter(Mandatory = $true)][string]$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-Output "[Deploy] job(s) by folder, Ignoring deployJobsByFileNames" $jobConfigFiles = Get-ChildItem -LiteralPath $localOutputPath -Filter "*.job.config.json" foreach ($jobConfig in $jobConfigFiles) { Publish-DatabricksJobToWorkspaceByName -config $config ` -bearerToken $bearerToken ` -jobConfig $jobConfig ` -removeSchedule $config.deployJobsByFolder.remove_schedule } } if (($config.deployJobsByFolder.deploy -eq $false) -and ($config.deployJobsByFileNames.Length -ge 1)) { Write-Output "[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) { Publish-DatabricksJobToWorkspaceByName -config $config ` -bearerToken $bearerToken ` -jobConfig $jobPath ` -removeSchedule $jobConfig.remove_schedule } else { Write-Error "Path $($jobPath) does not exist. Check file names are correct." } } } } catch { #uh oh throw $_.Exception } } |