我正在Visual Studio 2017中从事SSAS表格项目,我想在本地和天蓝色分析服务中自动化构建和部署(和测试)。该项目已连接到Azure Devops项目,并且可以正常工作。
但是在以天蓝色的开发人员构建和部署项目时,我非常费劲。我关注了有关该主题(https://notesfromthelifeboat.com/post/analysis-services-1-deployment/)的博客,并且作者创建了一些Powershell脚本,当我在Windows Powershell ISE上本地运行它们时,这些脚本可以在我的计算机上运行。但是,当我尝试在Powershell任务中使用相同的Powershell文件在devops上创建构建管道时,它失败了。我创建了一些变量,并设置了对powershell文件的引用。到目前为止一切顺利。当我尝试运行构建时,出现错误消息:
导入模块:未加载指定的模块'SqlServer' 因为在任何模块中都找不到有效的模块文件
似乎devops中的powershell无法加载Import-Module -Name SqlServer。我在网上搜索了一个解决方案,但到目前为止没有任何效果,并且ImpI的其他组合发现在Powershell ISe和Powershell ci-build任务之间$ env:PSModulePath环境变量之间存在很小的差异,但我不确定是否是问题所在。
如果您中有任何人知道如何解决此问题,或者对如何在本地部署SSAS表格模型,尤其是从构建/发行版到Azure部署(可能有些人具有自动化经验)有更好的解决方案,< / p>
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
答案 0 :(得分:0)
对于第三方模块,解决方案是修改$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
}