New-OctopusResource : Octopus Server returned an error: Value cannot be null.
Parameter name: source
Server exception:
Value cannot be null.
Parameter name: source
System.ArgumentNullException
I noticed that your script is using Get-OctopusResourceModel which is a cmdlet that belongs to the Octoposh module. That module hasn’t been updated since 2017 and its highly incompatible with current versions of the Octopus Server. I can 100% confirm this because I was the creator and sole maintainer of that project
I strongly recommend you to just rely on Octopus.client for all your automation needs and stop using Octoposh
The error you are getting is most likely happening because of 2 possible reasons:
Octoposh is giving you an old shape of the UserRoleResource object.
You are not populating all the properties needed on the UserRoleResource.
To work around that you’ll need to:
Modify the line that’s calling Get-OctopusResourceModel with: $NewUserRole = New-Object Octopus.Client.Model.UserRoleResource
Just like you are doing populating $NewUserRole.Name, populate the rest of the mandatory properties.
Finally, modify the line calling New-OctopusResource with $repository.UserRoles.Create($NewUserRole). If your $NewUserRole object is lacking mandatory properties, then the API will return an error telling you which ones.
Thank Dalmiro for valuable feedback. I am stuck in the id property for NewUSerRole. Not sure how the value can be the fetched from the OctopusDeploy & how can that be incremented.
for EX - Current custom user role has id = UserRole-1 and the next created UserRole should have UserRole-2, as the ID gets created/assigned at runtime(that’s what I believe).
In short, I need to find the max of UserRole id and increment it while creating new UserRole.
New-OctopusResource : Octopus Server returned an error: Value cannot be null.
Parameter name: source
Server exception:
Value cannot be null.
Parameter name: source
System.ArgumentNullException
For anyone else that runs into this issue: You don’t need to populate the Id property yourself. Leave it null and once you save it to the database successfully, octopus will return back the object with the Id populated.