|
| 1 | +jobs: |
| 2 | +- job: AgentJob |
| 3 | + displayName: Deploy Tabular Model |
| 4 | + pool: |
| 5 | + vmImage: 'windows-latest' |
| 6 | + steps: |
| 7 | + - checkout: self |
| 8 | + |
| 9 | + - task: PowerShell@2 |
| 10 | + displayName: 1. Download Tabular Editor |
| 11 | + inputs: |
| 12 | + targetType: inline |
| 13 | + script: "# Download URL for Tabular Editor portable: \n\n$TabularEditorUrl = \"https://github.com/otykier/TabularEditor/releases/download/2.16.5/TabularEditor.Portable.zip\"\n\n# Download destination (root of PowerShell script execution path): \n$DownloadDestination = join-path (get-location) \"TabularEditor.zip\" \necho($DownloadDestination)\n\n# Download from GitHub: \nInvoke-WebRequest -Uri $TabularEditorUrl -OutFile $DownloadDestination \n\n \n# Unzip Tabular Editor portable, and then delete the zip file:\n \nExpand-Archive -Path $DownloadDestination -DestinationPath (get-location).Path \n#Remove-Item $DownloadDestination " |
| 14 | + |
| 15 | + - task: CmdLine@2 |
| 16 | + displayName: 2. Best Practice Check |
| 17 | + inputs: |
| 18 | + script: TabularEditor.exe "$(SourceControlPath)\database.json" -A -T testbpa.trx -V |
| 19 | + |
| 20 | + - task: CopyFiles@2 |
| 21 | + displayName: 3. Copy Source Files |
| 22 | + inputs: |
| 23 | + SourceFolder: $(SourceControlPath) |
| 24 | + Contents: database.json |
| 25 | + TargetFolder: $(Build.ArtifactStagingDirectory)/PBIModel/Scripts |
| 26 | + |
| 27 | + - task: CmdLine@2 |
| 28 | + displayName: 4. Schema Check |
| 29 | + inputs: |
| 30 | + script: TabularEditor.exe "$(Build.ArtifactStagingDirectory)\PBIModel\Scripts\database.json" -S "Pipelines\SetCredentialsForValidation.csx" -SC -T testsc.trx -V |
| 31 | + |
| 32 | + - task: AzureKeyVault@2 |
| 33 | + displayName: 5. Read Key vault |
| 34 | + inputs: |
| 35 | + connectedServiceName: 'MyServiceConnectionName' # The name of the Service Connection to access the key vault |
| 36 | + KeyVaultName: 'MyKeyVauleName' # The name of the key vault |
| 37 | + SecretsFilter: 'mysecret' # This step copies the password to this variable, so in subseqent steps the name should match. If you change it here, do a find and replace to change it everywhere in this file. |
| 38 | + RunAsPreJob: true |
| 39 | + |
| 40 | + - task: CmdLine@2 |
| 41 | + displayName: 6. Deployment Check |
| 42 | + inputs: |
| 43 | + script: TabularEditor.exe "$(Build.ArtifactStagingDirectory)\PBIModel\Scripts\database.json" -D "Provider=MSOLAP;Data Source=$(DataSource);User ID=$(UserId);password=$(mysecret)" "$(DeploymentDB)" -O -C -E -W -T testdep.trx -V |
| 44 | + |
| 45 | + - task: CmdLine@2 |
| 46 | + displayName: 7. Create BIM File |
| 47 | + inputs: |
| 48 | + script: TabularEditor.exe "$(Build.SourcesDirectory)\$(SourceControlPath)" -BIM "$(Build.ArtifactStagingDirectory)\Model.bim" |
| 49 | + |
| 50 | + - task: PublishBuildArtifacts@1 |
| 51 | + displayName: 8. Publish Artifact DBArtifacts |
| 52 | + inputs: |
| 53 | + PathtoPublish: $(build.ArtifactStagingDirectory) |
| 54 | + ArtifactName: DBArtifacts |
| 55 | + |
| 56 | + - task: CmdLine@2 |
| 57 | + displayName: 9. Deploy BIM File |
| 58 | + inputs: |
| 59 | + script: TabularEditor.exe "$(Build.ArtifactStagingDirectory)\Model.bim" -S "$(ScriptFilePath)" -D "Provider=MSOLAP;Data Source=$(DataSource);User ID=$(UserId);password=$(mysecret)" "$(DeploymentDB)" -O -P -Y |
| 60 | + |
| 61 | + - task: PowerShell@2 |
| 62 | + displayName: '10. Refresh Power BI dataset' |
| 63 | + inputs: |
| 64 | + targetType: 'inline' |
| 65 | + script: | |
| 66 | + Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser -Force |
| 67 | + $SecurePassword = ConvertTo-SecureString “$(mysecret)” -AsPlainText -Force |
| 68 | + $credential = [System.Management.Automation.PSCredential]::new("$(AppId)", $SecurePassword) |
| 69 | + Connect-PowerBIServiceAccount -ServicePrincipal -Tenant $(TenantId) -Credential $credential |
| 70 | + $WorkspaceName = "$(DataSource)".split("/")[-1] |
| 71 | + $Workspace = Get-PowerBIWorkspace -Name $WorkspaceName |
| 72 | + $groupId = $Workspace[0].Id |
| 73 | + $Dataset = Get-PowerBIDataset -WorkspaceId $groupId | Where-Object {$_.name -eq "$(DeploymentDB)"} |
| 74 | + $datasetId = $Dataset[0].Id |
| 75 | +
|
| 76 | + Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$groupId/datasets/$datasetId/refreshes" -Method POST -WarningAction Ignore |
| 77 | +
|
0 commit comments