How to aggregate data from multiple tenants?

Is there a way to run a PowerShell script on multiple Tenants and aggregate the data collected from them? I have a script to run on about 100 Tenants. The script collects some information from the deployment target and I’d like to aggregate that data (or even just output it to a single log). I don’t want to have to browse 100 sets of task results to see the data.

I suppose you could create a file on each Tenant and upload an Artifact to the server… and then you’d have to do something to aggregate the 100 Artifacts. Just thinking there’s got to be an easier way.


Hey Jamie, thanks for reaching out!

I want to ensure I understand what you’re looking for. You want to be able to execute a PowerShell script form your Octopus server that:

  • Collects specific tenant information for ~100 tenants
  • Aggregates that data into a single structured data set
  • Creates an artifact that can be consumed to view all of that data without having to create ~100 individual reports

Did I miss anything from your intended use case explanation?

Hi Cory,

Yes that is essentially correct. I’m actually just running a small PowerShell script that is getting the the Tenant Name and the version of .NET installed on the tentacle. This needs to be run across approximately 100 tenants. The results don’t even have to be in an artifact… I’d be fine with just seeing the results aggregated in the Tasks logging so I could copy and paste it. :wink:

I should have mentioned I’m on an old version of Octopus 2018.8.8. We’ll probably be updating in the next few months… but for now this is what I’ve got.


No problem at all!

I’m going to take a look at this early next week and get you some more information. The good news is most of what you’re hoping for likely resides in the realm of PowerShell rather than Octopus specifically (formatting output, aggregating API call results into a singular object, etc.). I should be able to give you more specific endpoints and hopefully some useful psuedo code early next week!

Thank you. Have a great weekend.

Alright Jamie, I’ve got a couple of things that I think may help here -

  • Firstly, there’s an endpoint available via the Octopus API at GET /api/machines that will return a list of all of the deployment targets on your instance
    • These machine objects contain a property called TenantIds that is a list of any Tenant Ids associated with that deployment target
    • Paired with a call to GET /api/tenants, you can exchange those IDs for tenant names

While I think that approach is helpful, I also ended up with a few more questions. My approach assumes that you’re running a script against your Octopus instance rather than from within it. Rereading your initial request, it sounds like you’re wanting to select a series of tenants from within the Octopus UI, then run a script against that selected set and aggregate the results, is that right?

If so, I’ll have to do some more thinking on how you can best aggregate those when running a deployment per tenant. Please let me know your thoughts and we can keep trying to close in on exactly what you’re looking for!

Hopefully I can clarify this a bit.

  • I have an Octopus Project that Runs a Script step that runs a PowerShell against machines in RoleA
  • The script is reporting the highest .NET 4 version currently installed on the target
  • The script results are reflected in the resulting Task logging

This project can be run against 100 Tenants and I’d like to aggregate the data returned by the script so we don’t have browse 100 Task logs.

I’ve made some adjustments so that each Tenant now will create an Octopus Artifact (actually a CSV file) from the script results. I can then log into the Octopus Server itself and manually run a bit of PowerShell to consolidate the 100 Artifacts into a single CSV document.

Just wondering if there’s an easier way. Maybe the Artifacts can be accessed via the API? (I’m not used to using the API… obviously.)

That makes a lot of sense, thanks for the additional clarification!

It sounds like you’re on the right track - unfortunately there’s not a great way to aggregate that data in Octopus when pulling from disparate deployment targets like that.

Artifacts are accessible via the API - we have some scripted examples of how that works here. A possible option may be to create a deployment process that runs your artifact aggregation to spit out your mega csv at the end - certainly not the cleanest method, but should work to get you your concatenated/aggregated data from your created artifacts.

Let me know if you have more questions or run into any issues - sorry about the run around trying to understand the issue in the first place! :sweat_smile:

I’ve got something that is close to working.

Step 1: Create Artifact:
Runs a PowerShell script on a tenant targeting machines in a specific Role. It gathers some information from the server it is running on and creates an Octopus Artifact.

Step 2: Aggregate Artifacts:
Runs on the Default Worker Pool (in this case the Octopus Server) and using the API it grabs the Artifact created in Step 1 and appends the content to a file on the Octopus Server c:\temp\Consolidated.csv.

This seems to get the data collected and aggregated across multiple tenants.

Now it would be really cool if we could then create an Octopus Artifact from the Consolidated.csv file so that a user won’t have to actually go to the server and pick up the file. Is there a way to have Steps 1 and 2 complete for all tenants in the deployment and then run a 3rd step just once after 1 and 2 have completed for all the tenants in the deployment? (almost like a hybrid deployment where steps 1 and 2 are tenanted while step 3 would really be untenanted.)

Thanks for your input.

For now I’ve got a bit of a work-around by using two projects.

Project 1 is tenanted:

  • Step1 collects the information from each tenant and creates an Artifact.
  • Step 2 runs on the Octopus server and appends each Artifact into a consolidated file on the local filesystem.

Project 2 is untenanted:

  • Step 1 creates an Artifact from the consolidated file created by Project 1 Step 2
  • Step 2 removes the consolidated file from the server filesystem as it is now available as an Artifact

It’s not exactly elegant but it seems to get the job done.

Jamie, you beat me to it!

That’s exactly how I’d recommend running this in your current configuration. As you get closer to upgrading, you can likely abstract your second project (consolidation) into a runbook. You could then work out a trigger from your existing deployment that would automatically call consolidation after the files had been created.

I’m glad you’ve got this into a workable state, your approach outlined above seems like the best option given your current constraints. Feel free to reach out if your run into any additional issues!

Thanks for the feedback. It got me searching in the right direction.

Nice to know about the ‘runbook’ trigger possibility. We’re in the process of looking to get ourselves up to date and that capability would be helpful.

Take care.


1 Like

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