【问题标题】:Compress-Archive issue with TFS 2015TFS 2015 的压缩存档问题
【发布时间】:2018-12-05 12:21:58
【问题描述】:

我面临 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 字符:47 2018-06-26T17:29:14.3347355Z + ... e -Path .* -DestinationPath $(Build.ArtifactStagingDirectory)/$(Buil ... 2018-06-26T17:29:14.3348520Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2018-06-26T17:29:14.3348782Z + CategoryInfo : ObjectNotFound: (Build.ArtifactStagingDirectory:String) [], ParentContainsErrorRecordExc 2018-06-26T17:29:14.3348968Z 版本 2018-06-26T17:29:14.3349135Z + FullyQualifiedErrorId:CommandNotFoundException 2018-06-26T17:29:14.3349466Z
2018-06-26T17:29:14.5676478Z ##[错误]PowerShell 以代码“1”退出。

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

【问题讨论】:

    标签: powershell tfs azure-devops


    【解决方案1】:

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

    除了关于如何在TFS中访问Build变量,你应该先通过这个官方tutorial

    如果你想使用环境变量powershell脚本,你应该使用$env:BUILD_DEFINITIONNAME格式。

    【讨论】:

    • 由于我使用 VNEXT,我必须使用 $env:Build_ArtifactStagingDirectory,并且当我执行此 CMD "Compress-Archive -Path ${env:Build.ArtifactStagingDirectory} -DestinationPath ${env:Build .ArtifactStagingDirectory}\${env:Build.BuildId}.zip" 它抛出的路径为空或空。所以当我说 write-host "$env:Build_ArtifactStagingDirectory" 它给了我空字符串。我该如何调试?我需要手动创建这个变量吗?
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 2015-09-05
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-20
      相关资源
      最近更新 更多