【问题标题】:How to build and deploy SSAS tabular from VSTS through CI/CD locally and to Azure Analysis services如何在本地通过 CI/CD 从 VSTS 构建和部署 SSAS 表格并部署到 Azure 分析服务
【发布时间】:2018-12-18 17:13:24
【问题描述】:

我正在 Visual Studio 2017 中处理一个 SSAS 表格项目,我想在其中自动构建和部署(和测试)本地和 Azure 分析服务。该项目已连接到 Azure Devops 项目并且可以正常工作。

但是在 azure devops 中构建和部署项目时,我遇到了很多困难。我关注了有关此主题的博客 (https://notesfromthelifeboat.com/post/analysis-services-1-deployment/),并且当我在 Windows Powershell ISE 上本地运行它们时,作者创建了一些可以在我的计算机上运行的 powershell 脚本。但是,当我尝试在 Powershell 任务中使用相同的 Powershell 文件在 devops 上创建构建管道时,它失败了。我创建了一些变量并设置了对 powershell 文件的引用。到目前为止一切顺利。当我尝试运行构建时,我收到一条错误消息:

Import-Module : 未加载指定的模块“SqlServer” 因为在任何模块中都没有找到有效的模块文件

似乎 devops 中的 powershell 无法加载 Import-Module -Name SqlServer。我在网上搜索了一个解决方案,但到目前为止没有任何效果,并且 ImpI 的其他组合发现 Powershell ISe 和 Powershell ci-build 任务中的 $env:PSModulePath 环境变量存在微小差异,但我不确定这是否是问题所在。

如果你们中的任何人都知道如何解决这个问题,或者对如何在本地部署 SSAS 表格模型有更好的解决方案,尤其是从构建/发布部署到 azure(可能你们中的一些人有自动化经验)。

build setup on devops Error from running the build

Powershell 脚本

命令:.\deploy_model.ps1 -workspace c:\develop\tabular-automation -environment validation -analysisServicesUsername test_ssas -analysisServicesPassword test_ssas

  param(
    [Parameter(Mandatory)]
    [string]$workspace,
    [Parameter(Mandatory)]
    [string]$environment,
    [Parameter(Mandatory)]
    [string]$analysisServicesUsername,
    [Parameter(Mandatory)]
    [string]$analysisServicesPassword,
    [string]$databaseServer = "localhost",
    [string]$analysisServicesServer = "localhost"
)


Import-Module -Name SqlServer

$ErrorActionPreference = "Stop"

# Build the model
$msbuild = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe'
& "$msbuild" TabularExample.smproj "/p:Configuration=$environment" /t:Clean,Build /p:VisualStudioVersion=14.0

# Copy build outputs and deployment options to deployment directory
$deploymentDir = ".\deployment"
mkdir -Force $deploymentDir
cp "bin\$environment\*.*" $deploymentDir
cp .\deploymentoptions\*.* $deploymentDir

# Update deployment targets with parameters
$template = Get-Content .\deploymentoptions\Model.deploymenttargets
$expandedTemplate = $ExecutionContext.InvokeCommand.ExpandString($template)
$expandedTemplate | Set-Content "$deploymentDir\Model.deploymenttargets"

# Create the deployment script
Microsoft.AnalysisServices.Deployment.exe "$deploymentDir\Model.asdatabase" /s:"$deploymentDir\deploy.log" /o:"$deploymentDir\deploy.xmla" | Out-Default

# Deploy the model
$SECURE_PASSWORD = ConvertTo-SecureString $analysisServicesPassword -AsPlainText -Force
$CREDENTIAL = New-Object System.Management.Automation.PSCredential ($analysisServicesUsername, $SECURE_PASSWORD)
Invoke-ASCmd –InputFile "$workspace\$deploymentDir\deploy.xmla" -Server $analysisServicesServer -Credential $CREDENTIAL

【问题讨论】:

标签: powershell msbuild azure-devops ssas-tabular


【解决方案1】:

对于第三方模块,或者解决方案是修改$env:PSModulePath 以指向具有我们希望构建代理运行的模块版本的网络位置。我使用如下代码(我们还将 PSModulePath 设置为存储在同一个仓库中的自定义模块的相对路径,但我删除了这部分代码,因为您没有声明您有任何自定义模块)

我更喜欢这个而不是经常运行Install-Module,因为我可以更好地控制正在运行的模块版本,而且我不必担心我们的构建框会不断与 PowershellGallery 通信

try {
  Import-Module SQLServer -Force -ErrorAction Stop
}
catch {
$networkPath = "\\Network path to Modules\"
    if (!(Test-Path $networkPath)) {
      Write-Error "Can not set env:PSModulePath to the published location on the network" -ErrorAction Stop
    }
    else {
      if (!($env:PSModulePath -like "*;$networkPath*")) {
        $env:PSModulePath = $env:PSModulePath + ";$networkPath"
      }
    }
  }
  else {
    Write-Host "Setting the modulePath to $modulePath"
    if (!($env:PSModulePath -like "*;$modulePath*")) {
      $env:PSModulePath = $env:PSModulePath + ";$modulePath\"
    }
  }

  Import-Module SQLServer -Force -DisableNameChecking -ErrorAction Stop
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-01
    • 1970-01-01
    • 2020-01-10
    • 2023-03-16
    相关资源
    最近更新 更多