Api to find out who clicked deploy to

What is the recommended way to get all users who deployed (clicked the deploy to button) to production for a given project or all projects. I have looked at https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki/Deployments but the deployment api seems to omit the user, I can’t belive this is an oversight which makes me think I am going about this the wrong way…event’s api perhaps?

Hi Ben,

Thanks for getting in touch! I believe the best approach here is to use the Events API. You could use the following:

http://YOURSERVER/api/events/?regarding=PROJECT-ID&Category=DeploymentStarted

Let me know if that helps or if you have any further questions. :slight_smile:

Best regards,
Daniel

Thanks for your help

Couple of things…

a) using
http:///api/events/?regardingAll&Category=DeploymentStarted&Environment=Prod
doesn’t seem to restrict by Prod or DeploymentStarted as we see
DeploymentFailed categories.

{
“ItemType”: “Event”,
“IsStale”: false,
“TotalResults”: 31419,
“ItemsPerPage”: 30,
“Items”: [
{
“Id”: “Events-32173”,
“RelatedDocumentIds”: [
“Deployments-9717”,
“Projects-625”,
“Releases-7180”,
“Environments-81”,
“ServerTasks-32232”,
“Channels-466”,
“ProjectGroups-82”
],
“Category”: “DeploymentFailed”,
“UserId”: “users-system”,
“Username”: “system”,
“IdentityEstablishedWith”: “Unknown”,
“Occurred”: “2017-08-02T06:19:57.847+00:00”,
“Message”: “Deploy to test (#2) failed for OAuth - Reverse Proxy OS
Stack release 3.0.5 to test”,
“MessageHtml”: “Deploy to
test (#2)
failed for OAuth -
Reverse Proxy OS Stack
release 3.0.5 to test”,
“MessageReferences”: [
{
“ReferencedDocumentId”: “Deployments-9717”,
“StartIndex”: 0,
“Length”: 19
},
{
“ReferencedDocumentId”: “Projects-625”,
“StartIndex”: 32,
“Length”: 30
},
{
“ReferencedDocumentId”: “Releases-7180”,
“StartIndex”: 71,
“Length”: 5
},
{
“ReferencedDocumentId”: “Environments-81”,
“StartIndex”: 80,
“Length”: 4
}
],
“Comments”: null,
“Details”: null,
“Links”: {
“Self”: “/api/events/Events-32173”
}
},
{
“Id”: “Events-32172”,
“RelatedDocumentIds”: [
“Deployments-9717”,
“Projects-625”,
“Releases-7180”,
“Environments-81”,
“ServerTasks-32232”,
“Channels-466”,
“ProjectGroups-82”
],
“Category”: “DeploymentStarted”,
“UserId”: “users-system”,
“Username”: “system”,
“IdentityEstablishedWith”: “Unknown”,
“Occurred”: “2017-08-02T06:13:34.744+00:00”,

also, we are seeing most of these with user ‘system’ which isn’t even
listed in our users - what would that be?

Cheers,

Ben Shirley

untitled (326 Bytes)

untitled (4 KB)

untitled (306 Bytes)

untitled (221 Bytes)

Hi Ben,

Thanks for getting back. Sorry my initial answer didn’t help too much! I did some more digging and looked into this a bit further. It looks like I have a better answer for you here.

I have just tested and can confirm that the following works on my server:

http:///api/events/?eventCategories=DeploymentQueued&environments=Environments-1

This will search all events for DeploymentQueued where the environment value is Environments-1

DeploymentQueued - I believe we only log the user who queues the deployment, as the actual deployment is handled by the system account running the Octopus server. So in this case, i was able to see Daniel under users, as I used my Daniel account to click deploy.

Environments-1 - Our API does not generally look at the name of thing, but instead the ID. In this case, my Test environment has an id of Environments-1

Let me know how you go with this. :slight_smile:

Best regards,
Daniel

1 Like