Search code examples
c#clientoctopus-deploy

Octopus client, getting version from project name in C#


First of, I am completely new to octopus client, used it for the first time just before posting this.

So, I've been landed with this project to update the version number on a webpage monitoring some of our octopus deployed projects. I have been looking around the octopus client and not really gotten anywhere. The best I have so far is:

OctopusServerEndpoint endPoint = new OctopusServerEndpoint(server, apiKey);
OctopusRepository repo = new OctopusRepository(endPoint);
var releases = repo.Releases.FindAll();

From these releases I can get the ProjectId and even the Version, the issue is that releases is 600 strong and I am only looking for 15 of them.

The existing code I have to work from used to parse the version from local files so that is all out the window. Also, the existing code only deals with the actual names of the projects, like "AWOBridge", not their ProjectId, which is "Projects-27".

Right now my only option is to manually write up a keyList or map to correlate the names I have with the IDs in the octopus client, which I of course rather not since it is not very extendable or good code practice in my opinion.

So if anyone has any idea on how to use the names directly with octopus client and get the version number from that I would very much appriciate it.

I'll be getting down into octopus client while waiting. Let's see if I beat you to it!


Solution

  • Guess I beat you to it!

    I'll just leave an answer here if anyone ever has the same problem.

    I ended up using the dashboardto get what I needed:

    OctopusServerEndpoint endPoint = new OctopusServerEndpoint(server, apiKey);
    OctopusRepository repo = new OctopusRepository(endPoint);
    DashboardResource dash = repo.Dashboards.GetDashboard();
    List<DashboardItemResource> items = dash.Items;
    DashboardItemResource item = new DashboardItemResource();
    List<DashboardProjectResource> projs = dash.Projects;
    var projID = projs.Find(x => x.Name == projectName).Id;
    item = items.Find(x => x.ProjectId == projID && x.IsCurrent == true);
    

    The dashboard is great since it contains all the info that the web dashboard shows. So you can use Project, Release, Deployment and Environment with all the information they contain.

    Hope this helps someone in the future!