Answers: <p>You can use the Azure Devops build artifacts REST API to view the artifact properties e.g. <a href="https://dev.azure.com/%7Borganization%7D/%7Bproject%7D/_apis/build/builds/%7Bbuildid%7D/artifacts?api-version=7.2-preview.5" rel="nofollow noreferrer">https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildid}/artifacts?api-version=7.2-preview.5</a></p>
  <p>This returns a list of artifacts associated with the build and also lists custom properties you have added e.g.</p>
  <pre><code>        &quot;id&quot;: 47658199,
          &quot;name&quot;: &quot;SmashedManifest-Default&quot;,
          &quot;source&quot;: &quot;5e604834-27dc-574c-c96d-2ebcf0a82dfd&quot;,
          &quot;resource&quot;: {
              &quot;type&quot;: &quot;PipelineArtifact&quot;,
              &quot;data&quot;: &quot;651C4A252ABE81ECBA976C3C0043C9033202AF840E979BEF1D9C589AAADDFFGGEE&quot;,
              &quot;properties&quot;: {
                  &quot;user-AssetRetentionType&quot;: &quot;drop&quot;
  </code></pre>
  <p>In this case, the user-AssetRetentionType was added as a custom property.</p>
  <p>HTH</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-09-15T13:47:09.833Z
Answers: 2023-09-15T13:47:09.833Z
Answers: PaulieC1972
Answers: <p>From CHATGPT</p>
  <p>To access the metadata.json file and its content, you can use a script task in your pipeline.</p>
  <ul>
  <li><p>powershell: |</p>
  <h1>Specify the path to the artifact</h1>
  <p>$artifactPath = &quot;$(Pipeline.Workspace)/&quot;</p>
  <h1>Construct the path to the metadata file</h1>
  <p>$metadataPath = Join-Path $artifactPath &quot;metadata.json&quot;</p>
  <h1>Check if the metadata file exists</h1>
  <p>if (Test-Path -Path $metadataPath -PathType Leaf) {
  # Read the contents of metadata.json
  $metadataContent = Get-Content $metadataPath | ConvertFrom-Json
  Write-Host &quot;Metadata Content: $($metadataContent | ConvertTo-Json -Depth 100)&quot;</p>
  <pre><code>  # Access specific properties in the metadata
    $customProperty = $metadataContent.MyCustomProperty
    Write-Host &quot;Custom Property: $customProperty&quot;
  </code></pre>
  <p>} else {
  Write-Host &quot;Metadata file not found.&quot;
  }
  displayName: 'Access Metadata'</p>
  </li>
  </ul>
  <p>Apparently, the PublishPipelineArtifact task in Azure DevOps does not natively provide a way to directly retrieve or use custom properties set with the properties input elsewhere in your pipeline. The properties input is primarily used for associating metadata with the published artifacts, but retrieving and using these properties require some custom scripting and logic.</p>
  <p>To retrieve and use these custom properties in your pipeline, you can create a script task (e.g., PowerShell, Bash) that parses the metadata associated with the published artifact.</p>
  <ul>
  <li>powershell: |
  $artifactMetadata = Get-Content $(Build.ArtifactStagingDirectory)/myArtifact/metadata.json | ConvertFrom-Json
  $customProperty = $artifactMetadata.MyCustomProperty
  Write-Host &quot;Custom Property: $customProperty&quot;
  displayName: 'Retrieve Custom Properties'</li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2023-10-27T19:36:06.827Z
Answers: (Attempted) -1: I explicitly call out in my question the fact that the `metadata.json` file doesn't seem to exist.  If you can provide CI logs proving that you can indeed use it, or point me to an actual reference about using such a file, I'm happy to be proven wrong, but as it stands this is a non-working answer.
Answers: Clockwork-Muse
Answers: CC BY-SA 4.0
Answers: 2023-10-27T16:42:15.037Z
Answers: 2023-10-27T16:42:15.037Z
Answers: geeky_girl
Answers: <p>I have not tried this myself, but I think you could use it like:</p>
  <pre class="lang-yaml prettyprint-override"><code>- task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)'
      artifactName: 'my-artifact'
      publishLocation: 'pipeline'
      properties: |
        {
          &quot;user-MyCustomProperty1&quot;: &quot;Value1&quot;,
          &quot;user-MyCustomProperty2&quot;: &quot;Value2&quot;
        }
  </code></pre>
  <p>You could access this in the downstream tasks like:</p>
  <pre class="lang-yaml prettyprint-override"><code>- job: DownloadAndProcessArtifact
    displayName: 'Download and Process Artifact'
    steps:
    - script: echo &quot;Downloading artifact with MyCustomProperty1=Value1&quot;
      displayName: 'Download Artifact 1'
      condition: and(succeeded(), eq(dependencies.PublishPipelineArtifact.outputs['stepName']['user-MyCustomProperty1'], 'Value1'))
  
  
    - script: echo &quot;Downloading artifact with MyCustomProperty1=Value2&quot;
      displayName: 'Download Artifact 2'
      condition: and(succeeded(), eq(dependencies.PublishPipelineArtifact.outputs['stepName']['user-MyCustomProperty1'], 'Value2'))
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2023-09-11T23:14:58.507Z
Answers: You didn't name the step (so the dependency name wouldn't be available).  Fixing that, though, I can't get this to work (more specifically putting it into variables).  Also, the properties are implied to be associated with the artifact somehow, which this wouldn't actually do.  Still, this was something I hadn't considered.
Answers: Clockwork-Muse
Answers: CC BY-SA 4.0
Answers: 2023-09-01T15:47:44.613Z
Answers: 2023-09-12T10:51:48.790Z
Answers: 2023-09-12T10:51:48.790Z
Answers: geeky_girl
Body: <p>I've been using Azure Pipelines, but I'm stuck trying to find any examples or documentation on this one point.</p>
  <p>The <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/publish-pipeline-artifact-v1?view=azure-pipelines#inputs" rel="nofollow noreferrer"><code>PublishPipelineArtifact@1</code> documentation</a> lists a <code>properties</code> input that you can attach custom properties to... however, I can't find any documentation on how to retrieve or use these properties elsewhere.  There isn't anything in the documentation itself, nor in the equivalent download task.  These properties don't appear to be reflected in the UI at all either.</p>
  <p>Bing GPT seems to think that there should be a generated <code>metadata.json</code> file, but from simple tests no such file is created, and when pressed it acknowledges its references don't actually support what it's claiming.</p>
  <p>So how do I reference or use these custom properties?</p>
  
Tags: <azure-devops><azure-pipelines>
Title: How do I access custom artifact properties in Azure Devops pipelines?
UserDisplayName: Clockwork-Muse
ThreadText: # How do I access custom artifact properties in Azure Devops pipelines?
  
  (Asked by: username_0 on 2023-08-11)
  
  I've been using Azure Pipelines, but I'm stuck trying to find any examples or documentation on this one point.
  
  The [`PublishPipelineArtifact@1` documentation](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/publish-pipeline-artifact-v1?view=azure-pipelines#inputs) lists a `properties` input that you can attach custom properties to... however, I can't find any documentation on how to retrieve or use these properties elsewhere. There isn't anything in the documentation itself, nor in the equivalent download task. These properties don't appear to be reflected in the UI at all either.
  
  Bing GPT seems to think that there should be a generated `metadata.json` file, but from simple tests no such file is created, and when pressed it acknowledges its references don't actually support what it's claiming.
  
  So how do I reference or use these custom properties?
  
  **Tags:** azure-devops, azure-pipelines
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2023-09-15. Score: 0
  
  You can use the Azure Devops build artifacts REST API to view the artifact properties e.g. [https://dev.azure.com/{organization}/{project}/\_apis/build/builds/{buildid}/artifacts?api-version=7.2-preview.5](https://dev.azure.com/%7Borganization%7D/%7Bproject%7D/_apis/build/builds/%7Bbuildid%7D/artifacts?api-version=7.2-preview.5)
  
  This returns a list of artifacts associated with the build and also lists custom properties you have added e.g.
  
  ```
          "id": 47658199,
          "name": "SmashedManifest-Default",
          "source": "5e604834-27dc-574c-c96d-2ebcf0a82dfd",
          "resource": {
              "type": "PipelineArtifact",
              "data": "651C4A252ABE81ECBA976C3C0043C9033202AF840E979BEF1D9C589AAADDFFGGEE",
              "properties": {
                  "user-AssetRetentionType": "drop"
  
  ```
  
  In this case, the user-AssetRetentionType was added as a custom property.
  
  HTH
  
  
  ---
  
  ### Answer by username_2 on 2023-10-27. Score: 0
  
  From CHATGPT
  
  To access the metadata.json file and its content, you can use a script task in your pipeline.
  
  * powershell: |
  
    # Specify the path to the artifact
  
    $artifactPath = "$(Pipeline.Workspace)/"
  
    # Construct the path to the metadata file
  
    $metadataPath = Join-Path $artifactPath "metadata.json"
  
    # Check if the metadata file exists
  
    if (Test-Path -Path $metadataPath -PathType Leaf) {
    # Read the contents of metadata.json
    $metadataContent = Get-Content $metadataPath | ConvertFrom-Json
    Write-Host "Metadata Content: $($metadataContent | ConvertTo-Json -Depth 100)"
  
    ```
      # Access specific properties in the metadata
      $customProperty = $metadataContent.MyCustomProperty
      Write-Host "Custom Property: $customProperty"
  
    ```
  
    } else {
    Write-Host "Metadata file not found."
    }
    displayName: 'Access Metadata'
  
  Apparently, the PublishPipelineArtifact task in Azure DevOps does not natively provide a way to directly retrieve or use custom properties set with the properties input elsewhere in your pipeline. The properties input is primarily used for associating metadata with the published artifacts, but retrieving and using these properties require some custom scripting and logic.
  
  To retrieve and use these custom properties in your pipeline, you can create a script task (e.g., PowerShell, Bash) that parses the metadata associated with the published artifact.
  
  * powershell: |
    $artifactMetadata = Get-Content $(Build.ArtifactStagingDirectory)/myArtifact/metadata.json | ConvertFrom-Json
    $customProperty = $artifactMetadata.MyCustomProperty
    Write-Host "Custom Property: $customProperty"
    displayName: 'Retrieve Custom Properties'
  
  > **Comments:**
  > **username_0**: (Attempted) -1: I explicitly call out in my question the fact that the `metadata.json` file doesn't seem to exist.  If you can provide CI logs proving that you can indeed use it, or point me to an actual reference about using such a file, I'm happy to be proven wrong, but as it stands this is a non-working answer.  
  
  ---
  
  ### Answer by username_2 on 2023-09-01. Score: 0
  
  I have not tried this myself, but I think you could use it like:
  
  ```yaml
  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)'
      artifactName: 'my-artifact'
      publishLocation: 'pipeline'
      properties: |
        {
          "user-MyCustomProperty1": "Value1",
          "user-MyCustomProperty2": "Value2"
        }
  
  ```
  
  You could access this in the downstream tasks like:
  
  ```yaml
  - job: DownloadAndProcessArtifact
    displayName: 'Download and Process Artifact'
    steps:
    - script: echo "Downloading artifact with MyCustomProperty1=Value1"
      displayName: 'Download Artifact 1'
      condition: and(succeeded(), eq(dependencies.PublishPipelineArtifact.outputs['stepName']['user-MyCustomProperty1'], 'Value1'))
  
    - script: echo "Downloading artifact with MyCustomProperty1=Value2"
      displayName: 'Download Artifact 2'
      condition: and(succeeded(), eq(dependencies.PublishPipelineArtifact.outputs['stepName']['user-MyCustomProperty1'], 'Value2'))
  
  ```
  
  > **Comments:**
  > **username_0**: You didn't name the step (so the dependency name wouldn't be available).  Fixing that, though, I can't get this to work (more specifically putting it into variables).  Also, the properties are implied to be associated with the artifact somehow, which this wouldn't actually do.  Still, this was something I hadn't considered.  
  
  ---
  
  