Adding a variable set to a project

I am attempting to add an an existing library variable set to an exiting project using the client api…and getting the following exception “OctopusValidationException”.

The code looks like this:

var endpoint = new OctopusServerEndpoint(server, apiKey);
var repository = new OctopusRepository(endpoint);

LibraryVariableSetResource newSet = repository.LibraryVariableSets.FindOne(x => x.Name.Equals(“VARS”, StringComparison.InvariantCultureIgnoreCase));
ProjectResource project2 = repository.Projects.FindByName(“HC4.0b.2 DB Setup Only”); //octopus.Projects.FindByName(“PROJECT”);
project2.IncludedLibraryVariableSetIds.Add(newSet.Id);
repository.Projects.Modify(project2);

Hi Roger,

Thanks for reaching out. You need to add var before newSet and project2. This gist should do the trick:

Thanks!

Dalmiro

that did not solve the problem. The additional information for the OctopusValidationException is “The project must be assigned to a lifecycle”
The project IS assigned to a lifecycle….yet the error persists even after removing the strong typing as you suggest.

Hi Roger,

  • What version of Octopus are you running on your server?
  • What version of the Octopus.client do you have on your project?

Prior to 2.6, Octopus didn’t had Lifecycles, hence the Project resource didnt had a LifecycleID member. The error you are seeing makes me believe you are running a 2.6 server, but you are using an older version of the Octopus.client . Is if this is the case, updating the Octopus.client package on your solution should solve the problem

https://www.nuget.org/packages/Octopus.Client/

If this is not the case, please paste me the exact code you are using (in case you modified the gist i provided).

Thanks!

Dalmiro

An unhandled exception of type
’Octopus.Client.Exceptions.OctopusValidationException’
occurred in Octopus.Client.dll

Additional information: There was a problem with your request.

  • The project must be assigned to a lifecycle.

Octopus Deploy: 2.6.4.951

Hi Roger,

Are you running the exact same code of the Gist? I’ve updated the gist to print some properties, to make sure the Project has a valid lifecycle assigned to it. Please run the code just like it is on the gist and let me know the results

Thanks,

Dalmiro

Upgrading the octopus deploy nuget package solved the problem.
Thanks.