Issue Creating New Artifact Related to Deployment

The following code works fine:

Function New-ArtifactFromFile
Param (
[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!

By the way, in case it matters…

I’m using version of the Octopus.Client library, and my server version is 3.3.10.

  • I also tried this using 3.3.10 of the Octopus Client library to line it up with server version: same issue.

  • I tried doing a New-OctopusArtifact from within a deployment. I was able to add the artifact without issue. I see that it added both the ServerTask ID and the Deployment ID to the RelatedDocumentsId. I then tried using the exact same ID’s as New-OctopusArtifact (Environment, Project, Release, Deployment, and ServerTask ID’s) in the code above. It complained that both the ServerTask and the Deployment don’t exist.

Hi Louis,

Thanks for getting in touch.

Yes, you are correct. The only way to create an artifact related to a deployment (via the API) is from within a deployment itself. This is due to the way our API does validation on the related document ids (we ensure ids exist by checking the IdsInUse database view) …and deployment ids are not captured by this view, so it fails to find the deployment id.

When using the New-OctopusArtifact method from within a deployment script (like the example provided in our artifacts documentation), we are able to get the deployment id from the task that is executing and, in turn, store the deployment id against those artifacts.

Is there a reason you don’t want to create artifacts from within deployments themselves? If you’ve got a valid use-case, please let us know and we’ll consider providing the functionality you need.

Mark Siedle