No package version was specified for <package> (even though it's there)

I’m trying to create a release for a project but i can’t seem to create the release. I Get the following error message: “There was a problem with your request. - No package version was specified for <our package name”

But the package is found and added in the selectedPackes for the release as you can see in the screenshot. It fails when i call the create release
“// # Create release
release = repositoryForSpace.Releases.Create(release, false);”

We’re running self hosted octopus on version: 2019.6.7

hope you can help

// Nicki

Hey Nicki,

First of all, welcome to the Octopus Forums!

In order to dig in on this one, would you be able to private message me the full code that you’re running so I can dig in and try to reproduce it? If you are more comfortable with emailing it to support, you can do that as well with support@octopus.com.

Please let me know what you think.

Thanks,
Jeremy

Thank you for your reply. I’ve followed the guide on this page exactly: https://octopus.com/docs/octopus-rest-api/examples/create-and-deploy-a-release

I can send you the code i’m using right now, but you can’t call our octopus server which is on a private network, so i don’t know how much you can do with the code, when it’s the same as in the example. Everything until creating the release works.

Could it be an error in the version that we are running on our servers?

 class Program
{
    static void Main(string[] args)
    {
        OctopusRepository _repository;
        OctopusConfiguration _octopusConfig = OctopusConfiguration.GetInstance();

        var endpoint = new OctopusServerEndpoint(_octopusConfig.OctopusUrl, _octopusConfig.OctopusApiKey);
        _repository = new OctopusRepository(endpoint);

        // Get the space to work in
        var space = _repository.Spaces.FindByName(_octopusConfig.OctopusSpaceName);
        Console.WriteLine($"Using Space named {space.Name} with id {space.Id}");

        // Create space specific repository
        var repositoryForSpace = _repository.ForSpace(space);

        // Get project by name
        var project = repositoryForSpace.Projects.FindByName(_octopusConfig.OctopusProjectName);
        Console.WriteLine($"Using Project named {project.Name} with id {project.Id}");

        // Get channel by name
        var channel = repositoryForSpace.Channels.FindByName(project, _octopusConfig.OctopusChannelName);
        Console.WriteLine($"Using Channel named {channel.Name} with id {channel.Id}");

        // Get environment by name
        var environment = repositoryForSpace.Environments.FindByName(_octopusConfig.OctopusEnvironmentName);
        Console.WriteLine($"Using Environment named {environment.Name} with id {environment.Id}");

        // Get the deployment process template
        Console.WriteLine("Fetching deployment process template");
        var process = repositoryForSpace.DeploymentProcesses.Get(project.DeploymentProcessId);
        var template = repositoryForSpace.DeploymentProcesses.GetTemplate(process, channel);

        var release = new Octopus.Client.Model.ReleaseResource
        {
            ChannelId = channel.Id,
            ProjectId = project.Id,
            Version = template.NextVersionIncrement
        };

        // Set the package version to the latest for each package
        // If you have channel rules that dictate what versions can be used
        //  you'll need to account for that by overriding the selected package version
        Console.WriteLine("Getting action package versions");
        foreach (var package in template.Packages)
        {
            var feed = repositoryForSpace.Feeds.Get(package.FeedId);
            var latestPackage = repositoryForSpace.Feeds.GetVersions(feed, new[] { package.PackageId }).FirstOrDefault();

            var selectedPackage = new Octopus.Client.Model.SelectedPackage
            {
                ActionName = package.ActionName,
                Version = latestPackage.Version,
            };

            Console.WriteLine($"Using version {latestPackage.Version} for step {package.ActionName} package {package.PackageId}");
            release.SelectedPackages.Add(selectedPackage);
        }

        // # Create release

        release = repositoryForSpace.Releases.Create(release, false); // pass in $true if you want to ignore channel rules
        Console.WriteLine($"Release id is: {release.Id}");
    }
}


class OctopusConfiguration
{
    private static OctopusConfiguration OctopusConfig;

    private OctopusConfiguration()
    {
        OctopusUrl = ConfigurationManager.AppSettings["octopusUrl"];
        OctopusApiKey = ConfigurationManager.AppSettings["octopusApiKey"];
        OctopusSpaceName = ConfigurationManager.AppSettings["octopusSpaceName"];
        OctopusProjectName = ConfigurationManager.AppSettings["octopusProjectName"];
        OctopusChannelName = ConfigurationManager.AppSettings["octopusChannel"];
        OctopusEnvironmentName = ConfigurationManager.AppSettings["octopusEnvironmentName"];
    }

    public string OctopusUrl { get; }
    public string OctopusApiKey { get; }
    public string OctopusSpaceName { get; }
    public string OctopusProjectName { get; }
    public string OctopusChannelName { get; }
    public string OctopusEnvironmentName { get; }

    public static OctopusConfiguration GetInstance()
    {
        if (OctopusConfig == null)
        {
            OctopusConfig = new OctopusConfiguration();
        }
        return OctopusConfig;
    }
}

Hey Nicki,

I think I found the issue.

That script may have been created before PackageReferenceName was a variable within Octopus.

I added PackageReferenceName = package.PackageReferenceName

to

 var selectedPackage = new Octopus.Client.Model.SelectedPackage
    {
        ActionName = package.ActionName,
        Version = latestPackage.Version,
    };

to get

var selectedPackage = new Octopus.Client.Model.SelectedPackage
        {
            ActionName = package.ActionName,
            Version = latestPackage.Version,
            PackageReferenceName = package.PackageReferenceName
        };

And the script now works. I can’t confirm that this will work in all cases as I only tested it for one use-case, but please test it and let me know if it works for you.

Thanks,
Jeremy

That works. I’m a bit embarrassed i didn’t think of trying that…

Thank you so much!

1 Like

Hey Nicki,

No worries, you’re very welcome! It was a learning experience for me as well. I’m glad it worked for your use case.

Just a heads up in case you haven’t found our examples repo, we have one over here: https://github.com/OctopusDeploy/OctopusDeploy-Api

I think its pretty powershell/rest api heavy, but the examples may be worth it just for converting to C#/Octo.Client if you want to stick with that combination.

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.