Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何通过管道构建Id在ymal json中获取工件构建版本_Powershell_Yaml_Azure Devops Rest Api - Fatal编程技术网

Powershell 如何通过管道构建Id在ymal json中获取工件构建版本

Powershell 如何通过管道构建Id在ymal json中获取工件构建版本,powershell,yaml,azure-devops-rest-api,Powershell,Yaml,Azure Devops Rest Api,我正在一个Ymal管道上工作,我正在使用另一个管道中的构建工件。我可以使用以下代码下载工件: - task: DownloadBuildArtifacts@0 inputs: buildType:specific project: Test Project pipeline: TestInfrastructure-Rel branchName: 'refs/heads/release/preview' downloadTy

我正在一个Ymal管道上工作,我正在使用另一个管道中的构建工件。我可以使用以下代码下载工件:

- task: DownloadBuildArtifacts@0  

   inputs:       

   buildType:specific 

   project: Test Project 

   pipeline: TestInfrastructure-Rel

   branchName: 'refs/heads/release/preview'  

   downloadType: 'single'

   artifactName: Testartifact Packages

   buildVersionToDownload: 'latest'

   downloadPath: '$(System.DefaultWorkingDirectory)'
在上面的代码中,我知道我可以通过这个链接设置属性buildId来获取buildId

虽然我想知道软件包的版本是什么。我正在使用这个API从特定的构建中获取信息,但是工件版本号没有出现。 name}/{Project name}/_-api/build/builds/{buildid}/timeline/?api版本=5.1

基本上,我必须每天根据需要所有信息的特定管道运行情况创建一份报告

我还想通知您,虽然我无法将包版本设置为变量,但我已通过资源将包版本设置在管道中。如果我在任何变量中设置了包版本,它不会显示在构建管道ymal json中。当我使用名称}/{Project name}/_-API/build/builds/{buildid}/timeline/?API version=5.1运行API时,在图像中任务下方没有看到任何包版本。若我们可以从任何属性或任何东西设置ymal管道的版本,那个么我可以在下图中获得该版本

如果有人可以帮助我或指导我如何使用变量或PowerShell或azure PowerShell任务中的任何其他属性设置或传递版本号,这将非常有用

谢谢,您可以使用它从另一个管道消费构建工件。然后,您可以通过引用预定义变量
resources.pipeline.获得工件构建版本

关联管道资源中的工件将下载到
$(pipeline.Workspace)//

如果您想使用
DownloadBuildArtifacts
task和restapi来获取工件构建编号。你可以打电话。获取buildNumber后,可以使用
##vso[task.setvariable variable=buildVersion]
将其设置为变量。请参见以下示例:

resources:
  pipelines:
  - pipeline: sourcepipeline  # can be any string, this is the Alias in the predefined variables. identifier for the resource used in pipeline resource variables
    project: Test Project # project for the source; optional for current project
    source: TestInfrastructure-Rel  # name of the pipeline that produces an artifact
    branch: refs/heads/release/preview

pool: 
  vmImage: vs2017-win2016

steps:
- powershell: |
     echo "$(resources.pipeline.sourcepipeline.runName)"  #get the artifact build number
     echo "$(resources.pipeline.sourcepipeline.runId)"    #get the artifact build id
- powershell: |
        $url = $(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/<build.id>?api-version=5.1"

        $rawResponse = Invoke-RestMethod -UseDefaultCredentials -Uri $url -Method Get -ContentType "application/json" -Headers @{Authorization = "Bearer $(system.accesstoken)"}
        
        #pass build number to a variable 
        echo "##vso[task.setvariable variable=buildVersion]$($rawResponse.buildNumber)"
   
然后您将在yaml json中看到包版本,如下所示:


谢谢您的回复。我的做法与您提到的$(resources.pipeline.sourcepipeline.runName)相同,我的问题是,当我在变量中设置包版本时,它不会出现在ymal json中。我尝试了与您提到的echo“##vso[task.setvariable=buildVersion]$($rawResponse.buildNumber)”相同的方法,尽管在运行此API{Org name}/{Project name}时,我无法在ymal json中看到buildVersion变量/_api/build/builds/1234/timeline/?api version=5.1您的构建版本应该在PowerShell任务中出现,但我看不到。我真的不明白为什么您试图让包版本显示在yaml json中。我担心
时间线
restapi无法在任务中计算变量。如果要获取变量的值。您可以尝试在脚本任务中输出变量,然后使用
Builds-Get Build Log
rest api获取任务日志。@如果您尝试以方便的方式查看软件包版本,而不是打开生成摘要日志,则可以使用GauravJoshi。您可以尝试使用log命令
echo\vso[build.updatebuildnumber]$(resources.pipeline.sourcepipeline.runName)
更新您的buildnumber。通过这种方式,您可以直接在构建运行名称处看到包版本。我正在尝试生成这样的报告,其中必须在其中一列中显示发布包版本。为此,我尝试了多种方法,我只想在ymal json中获取变量值,但我不想在后续任务中使用该变量值。[![enter image description here][1][1][1]:@GauravJoshi我有一个解决方法,可以在timeline rest api返回的yaml json中显示包版本。检查以上更新。
- powershell: |
        $url = $(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/<build.id>?api-version=5.1"

        $rawResponse = Invoke-RestMethod -UseDefaultCredentials -Uri $url -Method Get -ContentType "application/json" -Headers @{Authorization = "Bearer $(system.accesstoken)"}
        
        #pass build number to a variable 
        echo "##vso[task.setvariable variable=buildVersion]$($rawResponse.buildNumber)"
   
steps:
- powershell: |
      echo "##vso[task.logissue type=warning]$(resources.pipeline.sourcepipeline.runName)"