Azure DevOps:如何从发布管道中的PowerShell脚本从构建Azure管道中检索构建工件?

问题描述 投票:0回答:1

我已经发布了一个生成工件,该工件已发布到$(Build.ArtifactStagingDirectory)/ drop,其工件名称为“ some_sidebar”,并且工件发布位置为Azure Pipeline。

如果我只有PowerShell Skript在发行任务中,现在如何在发行管道中检索该工件?

这里是代码的特定部分:

$path = ".\_some_sidebar\drop"
#$path = $(Build.Repository.LocalPath)
$SPFolderName = "Style Library/_some_sidebar";

# Upload template list
$status = "Uploading template list to Location: " + $SPFolderName
Write-Host $status
$te = Add-PnPFile -Path $path"\some_sidebar.js" -Folder $SPFolderName -Checkout
Set-PnPFileCheckedIn -Url $te.ServerRelativeUrl

我收到以下错误:

 Uploading template list to Location: Style Library/_some_sidebar
2020-01-16T09:51:20.5062033Z Add-PnPFile : Local file was not found.
2020-01-16T09:51:20.5062546Z At D:\_work\_temp\6d682160-e8a7-4c56-ab30-7ff8c40f2958.ps1:51 char:7
2020-01-16T09:51:20.5062832Z + $te = Add-PnPFile -Path $path"\some_sidebar.js" -Folder $SPFolderName  ...

[我假设天青管道中的构建工件路径是虚拟机中的某个路径...但是我不知道如何在shell脚本中指定该路径,或者无论如何该路径...?

azure powershell azure-pipelines release artifact
1个回答
0
投票

您应该可以使用System.ArtifactsDirectory。

这是我的示例流程,其中包括我如何使用上一步中的工件。在Powershell脚本中应该可以使用相同的变量。(此示例来自用于构建和发布的yaml管道。)

stages:
- stage: build
  displayName: 'Build and package solution'
  jobs:
  - job: buildsteps
    displayName: 'Steps to build and package'
    pool: 'PrivateVS2017'
    steps:
    - task: ArchiveFiles@2
      inputs:
        rootFolderOrFile: '$(Build.SourcesDirectory)/Web'
        includeRootFolder: true
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'it-service-wiki-build'
        publishLocation: 'Container'

- stage: deploy_to_development
  displayName: 'Deploy to development Environment'
  dependsOn: build
  jobs:
  - deployment: deploy
    displayName: 'Deploy the solution to Dev'
    pool: 'PrivateVS2017'
    environment: 'ITServiceWiki-Dev'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: DownloadBuildArtifacts@0
            inputs:
              buildType: 'current'
              buildVersionToDownload: 'latest'
              downloadType: 'single'
              ArtifactName: 'it-service-wiki-build'
              downloadPath: '$(System.ArtifactsDirectory)'
          - task: ExtractFiles@1
            inputs:
              archiveFilePatterns: '../a/**/$(Build.BuildId).zip'
              destinationFolder: '$(Build.DefaultWorkingDirectory)/$(Build.BuildId)'
              cleanDestinationFolder: true

下载工件后搜索zip时,请注意../a/**/。不知道/ a /是否相同,所有构建代理也可以在此处使用system.artifactsDirectory。

© www.soinside.com 2019 - 2024. All rights reserved.