PowerShell内联任务的Visual Studio构建任务问题 - Azure

时间:2018-03-13 05:57:31

标签: powershell azure-devops powershell-v3.0 azure-pipelines-release-pipeline azure-pipelines-build-task

我正在运行vsts build内联PowerShell脚本任务来为Azure云服务创建包。它工作正常,并从我的本地计算机创建包文件,但当我尝试从VSTS PowerShell内联任务运行时,它给出错误:

## [错误]找不到路径'D:\ a_tasks \ InlinePowershell_31f040e5-e040-4336-878a-59a493355534 \ 1.1.6 \ ServiceConfiguration.Cloud.Test.cscfg'因为它不存在。

下面是我的PowerShell内联脚本,它在以下行中失败:

Copy-Item $serviceConfigurationPath $packageOutDir

我真的很感谢你的帮助。

谢谢,

# This is the VSTS repository path
$workingDirectory = “$/DevCodeBase/ToolDevBranch1.33”
$webProjectName = “WebRole1”
$cloudProjectName = ‘ProjAzureDeployment’
$evv =’Test’
$cppack = ‘C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\cspack.exe’
$solutionDir = [string]::Format(“{0}”, $workingDirectory)
$webDir = [string]::Format(“{0}\{1}”, $workingDirectory, $webProjectName)
$packageOutDir = [string]::Format(“{0}\{1}”, $workingDirectory, $cloudProjectName)
$rolePropertyFile = [string]::Format(“{0}\{1}\{2}”, $workingDirectory, $cloudProjectName, “roleproperties.txt”)
# Create Role Properties File – This property file specifies the .Net framework against which webrole is going to run.
New-Item $rolePropertyFile -Type file -Force -Value “TargetFrameWorkVersion=v4.5” | Out-Null
New-Item $packageOutDir -Type directory -Force | Out-Null
# CSPack command Definition
$serviceDefinitionPath = [string]::Format(“{0}\{1}\ServiceDefinition.csdef”, $solutionDir, $cloudProjectName)
if ($evv -eq “Test”){
$serviceConfigurationPath = “ServiceConfiguration.Cloud.Test.cscfg”
}
else
{
$serviceConfigurationPath = [string]::Format(“{0}\{1}\ServiceConfiguration.Cloud.cscfg”, $solutionDir, $cloudProjectName)
}
$serviceRole = [string]::Format(“/role:{0};{1}”, $webProjectName, $webDir)
$rolePropertiesFile = [string]::Format(“/rolePropertiesFile:{0};{1}”, $webProjectName, $rolePropertyFile)
$sites = [string]::Format(“/sites:{0};Web;{1}”, $webProjectName, $webDir)
$packageOutput = [string]::Format(“/out:{0}\{1}.cspkg”, $packageOutDir, $cloudProjectName)
# $packageOutput = [string]::Format(“{0}\{1}.cspkg”, $packageOutDir, $cloudProjectName)
Write-Host $packageOutput
Write-Host $serviceConfigurationPath
# Build CSPKG file
& “C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\cspack.exe” $serviceDefinitionPath $serviceRole $rolePropertiesFile $sites $packageOutput /useCtpPackageFormat | Out-Null
Write-Host $serviceDefinitionPath
Write-Host $serviceRole
Write-Host $rolePropertiesFile
Write-Host $sites
Write-Host $packageOutput
Write-Host ‘before copy’
# Copy configuration file
Copy-Item $serviceConfigurationPath $packageOutDir
# Remove Role Properties File
Remove-Item -Path $rolePropertyFile -Force | Out-Null

1 个答案:

答案 0 :(得分:1)

在VSTS任务中,您必须指定绝对路径,否则脚本将查找为内联PowerShell脚本创建的临时目录。

例如,您可以将文件的路径作为参数提供 -filepath" $(System.DefaultWorkingDirectory)\ Solution \ config.json"

(有关您可以使用的变量列表,请查看here

如果要继续使用相对路径,可以移动到基于文件(即非内联)脚本并使用相对路径。