The following code works fine:
Function New-ArtifactFromFile
{
Param (
[Parameter(Mandatory)]
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string] $FilePath,
[string[]] $RelatedDocumentIds
)
$artifact = New-Object Octopus.Client.Model.ArtifactResource
$artifact.Filename = Split-Path -Path $FilePath -Leaf
if ($RelatedDocumentIds.Length -ne 0)
{
$artifact.RelatedDocumentIds = New-Object Octopus.Client.Model.ReferenceCollection -ArgumentList @(,$RelatedDocumentIds)
}
$artifact = $global:OctoUcsb.OctoClient.Repository.Artifacts.Create($artifact )
}
$relatedDocumentIds = @(“Projects-124”,“Environments-1”,“Releases-260”)
#$relatedDocumentIds = @(“Projects-124”,“Environments-1”,“Releases-260”,“Deployments-347”)
New-ArtifactFromFile -FilePath “C:\Users\tourtellotte-l\Desktop\testArtifact.txt” -RelatedDocumentIds $relatedDocumentIds
However, if I comment out $relatedDocumentIds = @(“Projects-124”,“Environments-1”,“Releases-260”) and use $relatedDocumentIds = @(“Projects-124”,“Environments-1”,“Releases-260”,“Deployments-347”) instead (or even just the project, environment, and deployment ID’s), I get the following exception.
Exception calling “Create” with “1” argument(s): "There was a problem with your request.
- One or more referenced resources do not exist: “Deployments-347” provided for RelatedDocumentIds
However, Deployments-347 exists.
I’m guessing that the real issue is that I can only create an artifact related to a deployment from within the deployment itself. Is that true?
Thanks for your help!