0

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 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?

3 Answers 3

0

I have not tried this myself, but I think you could use it like:

- 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:

- 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'))
1
  • 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. Sep 11 at 23:14
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

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

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'
1
  • (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. Oct 27 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.