TFS 2015的压缩存档问题

时间:2018-06-26 17:36:28

标签: powershell tfs azure-devops

我遇到Compress-Archive cmd行问题。我需要压缩放置文件(某些文件),并将压缩的.rar推送到Azure blob存储。

在VSTS中,我们有默认的压缩任务&对我有用,但是在TFS 2015中,我使用powershell cmd

Compress-Archive -Path $(Build.ArtifactStagingDirectory)\* -DestinationPath $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip

我结束了。出现错误

2018-06-26T17:29:08.5918176Z生成脚本。 2018-06-26T17:29:08.5918734Z格式化的命令:。 'D:\ a \ 1 \ s \ arch.ps1' 2018-06-26T17:29:09.3003116Z ## [command]“ C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe” -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command“。'D:\ a_temp \ e2b5fc08-c599-49ec-bbd6-8a4a69f8d977.ps1'“ 2018-06-26T17:29:14.3345598Z Build.ArtifactStagingDirectory:术语'Build.ArtifactStagingDirectory'不被识别为cmdlet的名称, 2018-06-26T17:29:14.3345966Z函数,脚本文件或可操作程序。检查名称的拼写,或者是否包含路径,请确认 2018-06-26T17:29:14.3346099Z路径正确,然后重试。 2018-06-26T17:29:14.3346952Z在D:\ a \ 1 \ s \ arch.ps1:5 char:47 2018-06-26T17:29:14.3347355Z + ... e -Path。* -DestinationPath $(Build.ArtifactStagingDirectory)/ $(构建... 2018-06-26T17:29:14.3348520Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2018-06-26T17:29:14.3348782Z + CategoryInfo:ObjectNotFound:((Build.ArtifactStagingDirectory:String)[],ParentContainsErrorRecordExc 2018-06-26T17:29:14.3348968Z eption 2018-06-26T17:29:14.3349135Z + FullyQualifiedErrorId:CommandNotFoundException 2018-06-26T17:29:14.3349466Z
2018-06-26T17:29:14.5676478Z ## [error] PowerShell退出,代码为'1'。

如何在Powershell脚本中访问构建变量?有人可以指导我吗?

2 个答案:

答案 0 :(得分:0)

这是假设您使用的是TFS 2015中引入的较新的构建系统,而不是XAML构建。

在脚本中运行时,这些值存储为环境变量。 可以如下访问它们,例如: $env:Build_ArtifactStagingDirectory

答案 1 :(得分:0)

错误信息为 CommandNotFoundException ,您可能使用了错误的命令格式-Compress-Archive。尝试将$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip更改为$(Build.ArtifactStagingDirectory)\$(Build.BuildId).zip

除了如何在TFS中访问Build变量外,您还应该首先通过此官方tutorial

enter image description here

如果要使用环境变量Powershell脚本,则应使用$env:BUILD_DEFINITIONNAME格式。