【问题标题】:Publishing Pipeline Artifacts for use in another pipeline发布管道工件以在另一个管道中使用
【发布时间】:2020-05-22 11:46:35
【问题描述】:

我正在尝试在构建期间发布几个管道工件,以便我可以在构建另一个解决方案时使用它们。

我的第一个构建使用以下 yaml 构建和测试解决方案

- stage: build_test_release
    displayName: Build
    pool:
      vmImage: 'windows-latest'
    variables:
      solution: '**/*.sln'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'

    jobs:
      - job: build
        steps:
        - task: NuGetToolInstaller@1
        - task: NuGetCommand@2
          inputs:
            restoreSolution: '$(solution)'
        - task: VSBuild@1
          inputs:
            solution: '$(solution)'
            msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
            platform: '$(buildPlatform)'
            configuration: '$(buildConfiguration)'
        - task: VSTest@2
          inputs:
            platform: '$(buildPlatform)'
            configuration: '$(buildConfiguration)'

这一切都很好,我已经能够在同一个文件中使用这个 yaml 进行部署

    - task: AzureRmWebAppDeployment@4
      inputs:
        ConnectionType: 'AzureRM'
        azureSubscription: 'azuresubscription'
        appType: 'webApp'
        WebAppName: 'webappname'
        deployToSlotOrASE: true
        ResourceGroupName: 'resourcegroupname'
        SlotName: 'staging'
        packageForLinux: '$(build.artifactStagingDirectory)/**/projectToPublish.zip'

我现在正在尝试发布一些作为管道工件构建的项目,以便我可以在构建引用它们的另一个解决方案中使用它们。以下发布任务给了我错误:

"##[错误]路径不存在:D:\a\1\a**\projectToPublish.zip"

    - task: PublishPipelineArtifact@1
      inputs:
        targetPath: '$(build.artifactStagingDirectory)/**/projectToPublish.zip'
        artifact: 'artifactname'
        publishLocation: 'pipeline'

我在这里缺少什么?我一直在考虑将两个解决方案引用的项目移动到他们自己的解决方案中,并将它们添加为 nuget 包或类似的东西。我尝试发布为要在第二个解决方案中使用的工件的项目都是 WCF 客户端项目。

谢谢!

【问题讨论】:

  • 嗨,汤姆,您的问题有更新吗?下面托马斯的回答是否有助于解决您的问题?检查this rule,如果有帮助,您可以考虑接受它作为答案。如果问题仍然阻碍您,请随时告诉我。这只是一个提醒:)

标签: azure-devops azure-pipelines azure-pipelines-build-task azure-artifacts azure-pipelines-yaml


【解决方案1】:

问题是您正在使用的任务发布管道工件不支持“文件或目录路径”参数的通配符。对于此任务,$(build.artifactStagingDirectory) 替换为 D:\a\1\a\,在名为 a 的第二个目录中,Azure DevOps 正在寻找名为 ** 的子目录,该目录不存在并导致显示的错误。您正在使用的另一个任务AzureRmWebAppDeployment@4 确实支持通配符。

参见下图,其中 Azure DevOps 在 UI 中显示 PublishPipelineArtifact@1 任务不支持 targetPath 中的通配符:

其次,我想知道您为什么要使用通配符,因为任务VSBuild@1 只会将包放在build.artifactStagingDirectory 中,这应该使路径$(build.artifactStagingDirectory)/projectToPublish.zip 来定位包。

【讨论】:

    【解决方案2】:

    AzureRmWebAppDeployment@4 你有

    '$(build.artifactStagingDirectory)/**/WebProjectToPublish.zip'
    

    PublishPipelineArtifact@1 中你有不同的名字

    '$(build.artifactStagingDirectory)/**/projectToPublish.zip'
    

    【讨论】:

    • 抱歉,该名称只是一个占位符,用于隐藏项目的实际名称。它们在实际的 yaml 文件中是相同的,我已经更新发布以显示这一点。
    • PublishPipelineArtifactVSBuild 是同一份工作吗?
    • 是的,所有任务都在同一个工作中
    • 您能否在VSBuild 步骤之后和PublishPipelineArtifact 之前的两个位置添加此步骤- bash: ls '$(build.artifactStagingDirectory)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2022-08-11
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多