首页 > 解决方案 > 使用 UniversalPackages@0 发布文件 - “提供的路径无效。”

问题描述

我正在尝试将文件(Helloworld.txt)发布到我的Universal Packages目录,以传递到我的 Release Piepline 中的不同阶段(使用UniversalPackages@0)。

我终其一生都无法弄清楚如何让它发挥作用。

我正在尝试关注此 KB,但它让我感到困惑:

https://docs.microsoft.com/en-us/azure/devops/pipelines/artifacts/universal-packages?view=azure-devops&tabs=yaml

例如,我无法确定vstsFeedPublish是什么,也不知道vstsFeedPackagePublish是否可以是我当场编造的新名称,或者它是否实际上是现有文件/文件夹的名称。

我输入错误的“路径”导致失败?

阶段部署步骤:

在此处输入图像描述

Helloworld 输出到 TXT:

cd $(Build.ArtifactStagingDirectory)
"$(System.DefaultWorkingDirectory)/Helloworld Build/Helloworld EXE Folder/Helloworld.exe" >> WriteLineOutput.txt

cd进入$(Build.ArtifactStagingDirectory)第一个是因为那是默认文件夹UniversalPackages@0看起来要发布文件,所以我想WriteLineOutput.txt在那里生成。

将输出 TXT 发布到通用目录 (YAML):

steps:
- task: UniversalPackages@0
  displayName: 'Publish Output TXT to Universal Dir'
  inputs:
    command: publish
    vstsFeed: '0a3a9abd-83fd-495f-967b-e986c523f2d2'
    vstsPackageVersion: 1
    vstsFeedPublish: '0a3a9abd-83fd-495f-967b-e986c523f2d2'
    vstsFeedPackagePublish: 'writelineoutput-txt'
    versionOption: minor
    packagePublishDescription: 'TXT output from Helloworld.exe'

工作目录结构:

在此处输入图像描述

“将输出 TXT 发布到通用目录”任务输出:

2019-12-02T03:35:35.2264352Z ##[section]Starting: Publish Output TXT to Universal Dir
2019-12-02T03:35:35.2381247Z ==============================================================================
2019-12-02T03:35:35.2381328Z Task         : Universal packages
2019-12-02T03:35:35.2381359Z Description  : Download or publish Universal Packages
2019-12-02T03:35:35.2381412Z Version      : 0.160.1
2019-12-02T03:35:35.2381461Z Author       : Microsoft Corporation
2019-12-02T03:35:35.2381490Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks
2019-12-02T03:35:35.2381520Z ==============================================================================
2019-12-02T03:35:36.0651445Z SYSTEMVSSCONNECTION exists true
2019-12-02T03:35:36.6058302Z Downloading: https://0t3vsblobprodcus362.vsblob.vsassets.io/artifacttool/artifacttool-win10-x64-Release_0.2.128.zip?sv=2017-04-17&sr=b&sig=tHZQU3V2DuXcC0Y1xnmzB7Zw7kMdjJSijWVDiztc9UE%3D&spr=https&se=2019-12-02T04%3A35%3A37Z&sp=r&P1=1575261037&P2=11&P3=2&P4=LS6Ffab5P%2bb8Q9r3aGsGLlK9ELRD6bRxxlTkDc5aEc8%3d
2019-12-02T03:35:39.3862184Z Caching tool: ArtifactTool 0.2.128 x64
2019-12-02T03:35:40.4414172Z SYSTEMVSSCONNECTION exists true
2019-12-02T03:35:41.4415128Z Publishing package: writelineoutput-txt, version: 0.1.0 using feed id: 65dc653c-5c3b-771c-b308-34b199d8fcee, project: null
2019-12-02T03:35:41.4469092Z [command]C:\hostedtoolcache\windows\ArtifactTool\0.2.128\x64\ArtifactTool.exe universal publish --feed 65dc653c-5c3b-771c-b308-34b199d8fcee --service https://vsrm.dev.azure.com/sawtooth-capstone/ --package-name writelineoutput-txt --package-version 0.1.0 --path D:\a\r1\a\$(Build.ArtifactStagingDirectory) --patvar UNIVERSAL_PUBLISH_PAT --verbosity None --description "TXT output from Helloworld.exe"
2019-12-02T03:35:44.0492154Z {"@t":"2019-12-02T03:35:43.3152933Z","@m":"ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session 23e076ea-5122-4c06-b92a-2aef5974defd","@i":"8778ba0f","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.315Z"}
2019-12-02T03:35:44.0493421Z {"@t":"2019-12-02T03:35:43.7170274Z","@m":"Ensuring that the package does not yet exist...","@i":"40e01e14","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.717Z"}
2019-12-02T03:35:44.0494251Z {"@t":"2019-12-02T03:35:43.8900269Z","@m":"Package does not yet exist","@i":"c781eca5","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.890Z"}
2019-12-02T03:35:44.0494769Z {"@t":"2019-12-02T03:35:43.8913512Z","@m":"Pushing content...","@i":"3aa40378","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.891Z"}
2019-12-02T03:35:44.0495859Z {"@t":"2019-12-02T03:35:43.9060246Z","@m":"DedupManifestArtifactClient will correlate http requests with X-TFS-Session 23e076ea-5122-4c06-b92a-2aef5974defd","@i":"09a6f3ce","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.906Z"}
2019-12-02T03:35:44.0496478Z {"@t":"2019-12-02T03:35:44.0301714Z","@m":"The path provided is invalid.","@i":"05178f7d","@l":"Error","SourceContext":"ArtifactTool.Program","UtcTimestamp":"2019-12-02 03:35:44.030Z"}
2019-12-02T03:35:44.0776082Z ##[error]Error: An unexpected error occurred while trying to push the package. Exit code(16) and error({"@t":"2019-12-02T03:35:43.3152933Z","@m":"ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session 23e076ea-5122-4c06-b92a-2aef5974defd","@i":"8778ba0f","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.315Z"}
{"@t":"2019-12-02T03:35:43.7170274Z","@m":"Ensuring that the package does not yet exist...","@i":"40e01e14","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.717Z"}
{"@t":"2019-12-02T03:35:43.8900269Z","@m":"Package does not yet exist","@i":"c781eca5","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.890Z"}
{"@t":"2019-12-02T03:35:43.8913512Z","@m":"Pushing content...","@i":"3aa40378","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.891Z"}
{"@t":"2019-12-02T03:35:43.9060246Z","@m":"DedupManifestArtifactClient will correlate http requests with X-TFS-Session 23e076ea-5122-4c06-b92a-2aef5974defd","@i":"09a6f3ce","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.906Z"}
{"@t":"2019-12-02T03:35:44.0301714Z","@m":"The path provided is invalid.","@i":"05178f7d","@l":"Error","SourceContext":"ArtifactTool.Program","UtcTimestamp":"2019-12-02 03:35:44.030Z"})
2019-12-02T03:35:44.0789627Z ##[error]Packages failed to publish
2019-12-02T03:35:44.0898947Z ##[section]Finishing: Publish Output TXT to Universal Dir

关键线:

2019-12-02T03:35:44.0496478Z {"@t":"2019-12-02T03:35:44.0301714Z","@m":"The path provided is invalid.","@i":"05178f7d","@l":"Error","SourceContext":"ArtifactTool.Program","UtcTimestamp":"2019-12-02 03:35:44.030Z"}
2019-12-02T03:35:44.0776082Z ##[error]Error: An unexpected error occurred while trying to push the package. Exit code(16) and error({"@t":"2019-12-02T03:35:43.3152933Z","@m":"ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session 23e076ea-5122-4c06-b92a-2aef5974defd","@i":"8778ba0f","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2019-12-02 03:35:43.315Z"}

编辑:

好吧,我阅读了使用Build管道发布工件并使用Release管道运行/测试它们的最佳实践,所以我决定只从Build管道发布工件,而不是在测试期间再次尝试制作相同的Helloworld.txt发布管道。但是,如果有人可以帮助我弄清楚如何将在发布管道中创建的新文件发布到通用包目录中,我愿意接受不可避免的反对票。

标签: azure-devopsazure-pipelinesazure-pipelines-release-pipeline

解决方案


我最好建议您调用在Buildexe中生成txt文件。然后将它们发布为工件以发布管道。然后您可以轻松地在发布管道中选择文件。HelloWord.txt

此任务可用于构建和发布管道。在 Build 和 release 中应用此任务之间的区别只是Path to file(s) to publish您非常困惑的值。

对于发布管道:

如果您想要发布HelloWord.txt成包,只需单击在此处输入图像描述,然后从中选择相应的文件HelloWord.txt

在此处输入图像描述

那么,它的价值应该是多少$(System.DefaultWorkingDirectory)/{Source alias}/{artifact name}/s/HelloWorld.txt

注意:这种方式适用于将txt生成的内容放入构建管道,然后将它们发布为artifact并在发布管道中使用。


Build pipeline类似,您也可以从该按钮中选择文件。对于其 YAML 格式,只需输入文件名,如:

  inputs:
    command: publish
    publishDirectory: 'azure-pipelines.txt'
    vstsFeedPublish: '*****'
    vstsFeedPackagePublish: merlin
    versionOption: custom
    versionPublish: 0.0.1
    packagePublishDescription: published in 2019/12/2

如果 azure-pipelines.txt 文件位于文件夹下,只需将其输入为{folder name}/azure-pipelines.txt.

在您的问题中,如果您想将文件生成和包发布都放在构建管道中。因为我不太清楚你的HellowWorld.exe剧本怎么样。的位置HelloWorld.txt由您的脚本决定。如果您没有在脚本中定义生成的文件位置,默认情况下,此txt文件路径应与exe. 根据您分享的图片,它的路径似乎是HelloWorld EXE Folder/HelloWorld.txt。我建议您可以先使用私有代理来运行此构建以确认其(.txt)路径。


vstsFeedPublish应该是您在项目中创建的现有提要。这里 不能是管道执行前不存在的新名称。


vstsFeedPackagePublish是您希望它存储在提要中的包名称。以我为例,这里我将其命名为merlin. 发布完成后:

在此处输入图像描述

您可以指定一个新名称或使用现有名称。使用新名称意味着在Feed中创建一个新包,使用现有名称只是意味着版本增量。


推荐阅读