Failed to create External Feed using API create function powershell

Hi Team,

I tried creating feed in octopus using powershell. But I am getting error " Exception calling “Create” with “1” argument(s): “Octopus Server returned an error: Unable to determine type to deserialize. FeedType None does not map to a known
type”.

I could not assign FeedType also as it is readonly field. Could you please help ASAP?

Please find my code below.

If ($repository.Feeds.FindByName($FeedName)){

write-output “Feed already exists: $feedname”

}

else{

$Properties = @{
FeedUri= $FeedURI
Name= $FeedName
}

$FeedObj = New-Object Octopus.Client.Model.FeedResource -Property $Properties

$repository.Feeds.Create($FeedObj)

}

Thanks in Advance
Kiruthika

Hi Kiruthika,

Thanks for reaching out.

I wrote some code over here that seems to do the trick. You want to create the type of resource that you want and add that to the feeds resource.

For instance for a docker feed, you will create:

$dockerfeed = New-Object Octopus.Client.Model.DockerFeedResource

There is also GitHubFeedResource, AwsElasticContainerRegistryFeedResource, BuiltInFeedResouce, HelmFeedResource, MavenFeedResource, and NuGetFeedResource

This is example code for Docker feeds (I have added extra code to dig into the space repository on my Octopus Instance):

Add-Type -Path 'C:\temp\Octopus.Client.dll' 
$OctopusUrl = ""
$ApiKey = ""
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $OctopusUrl,$ApiKey
$client = new-object Octopus.Client.OctopusClient $endpoint

#open up space repository to modify it
$spaceName = "Default"
$space = $client.ForSystem().Spaces.FindByName($spaceName)
$spaceRepository = $client.ForSpace($space)

#docker feed variables
$FeedName = "Fake Docker"
$FeedURI = "http://fakepath.com"
$RegistryPath = ""

If ($spaceRepository.Feeds.FindByName($FeedName)){

write-output “Feed already exists: $feedname”

}

else{
$dockerfeed = New-Object Octopus.Client.Model.DockerFeedResource
$dockerfeed.RegistryPath = $RegistryPath
$dockerfeed.FeedUri = $FeedURI
$dockerfeed.Name = $FeedName
$spacerepository.Feeds.Create($dockerfeed)


}

As always, please test code given by support or on our github thoroughly before putting into production. It is not guaranteed to work in every setup.

You can see the types of models at this repository here: https://github.com/OctopusDeploy/OctopusClients/tree/4062372580d70c0da609b82c39fb1da14422b38c/source/Octopus.Client/Model

Please let me know if it works for you or if you need more assistance with it.

Thanks,
Jeremy

Hi Jeremy,

Thanks for the quick reply. It is working fine now.

1 Like

Hi Kiruthika,

You’re very welcome! Thank you for letting me know.

I hope you have a great weekend.

Thanks,
Jeremy

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.