Retrieve all Deployments details for a specific Day

Hi Team,
I am trying to retrieve the deployments completed for a day by using C#. So far I was not able to exactly get any method which is able to do that. I got some code to extract the event details but it was not extracting the data for a specific date.

I am looking for a code which will extract the deployments data for a specific date[date can be passed as an parameter] and also the retrieved data should contain [Environment/Tenant/State(success/fail)/time taken ]etc…

Please let me know if we have already have an C# Code which I can use to get this data. Else second option is if there is any powershell script for the same ?

Thanks,
Sujesh Sasidharan

Hi Sujesh,

Thanks for getting in touch! I’m wondering if you have seen our example repository on GitHub? We have a handful of helpful C# scripts using the octopus.client which should help you get started with any API scripting you need to do.

All of the information available in the portal should be available through the API. I think the deployments endpoint will be a good place to start. You can search based on the creation date and have it return the details about that deployment.

Let me know if this helps or if you have any further questions at all.

Best regards,
Daniel

Thanks @Daniel_Fischer . this link was useful, I have already tried this code and the problem is it is trying to scan all the pages to get the details and is taking more time to complete for a single environment. please note that we have 1000s of pages. So could you please help me here on how I can pass the date in the code shown below. so that it retrieves data just for a day or for a specific date passed as a parameter.

Hi @sujeshsasi

One code example of getting all deployments by date would be to use the FindAll call and then use a LINQ query to focus your results to the last day. I’ve put a simple example below.

spaceRepo.Deployments.FindAll().Where(d => d.LastModifiedOn > DateTime.Now.AddDays(-1)).ToList();

This may still bring up the performance issues with the number of deployments you have.

Another option would be to use the Events endpoint instead. This has native access using dates in the To and From parameters. These two parameters use strings rather than DateTime variables. I’ve put an example below.

spaceRepo.Events.List(from: DateTime.Now.AddDays(-1).ToString(), to: DateTime.Now.ToString());

The above illustrates the example, and the actual string parsing of the dates may need to be changed if the database requires a specific format.

Events do not include the time taken for deployments, so if this is something you desire, then you will have to use this event list and use it to search for individual deployments.

Should either of the above not work for you, or their performance isn’t desirable, I recommend looking at reporting tools to see if they would be able to retrieve the data that you need. The page I’ve linked details how you can use the raw data we provide from Octopus to query what you need without utilising the .NET Client or API.

Let us know if you have any further questions or issues arise!
Kind Regards

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