Get task history using API

usability
(Mohamed HAJJI) #1

Hello i need to the get the user responsible for lunching a specific task , in octopus this information seems to be saved under Task History (when,who,what) , i was wandering how i can get this info based on taskID or deploymentID ,
thx in advance

(Daniel Fischer) #3

Hi @MOMO

Thanks for getting in touch! I have just whipped up a quick script to help you do this. It will search for the ServerTasks-ID you enter, and look in the Octopus events (Audit log) for any events matching that ID and with a status of Queued. We only expose the user who started a deployment on the Queued event as the System user is used to do everything after that.

Here is my PowerShell to return a message like:
The account which : Deployed OutputVariables release 0.0.21 to Dev : Was admin

cd C:\MyScripts\Octopus.Client
Add-Type -Path 'Octopus.Client.dll' 

$apikey = 'API-KEY' # Get this from your profile
$octopusURI = 'http://OctopusServer/' # Your server address

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

$serverTasksID = "ServerTasks-159414"

$repository.Events.FindMany(
    {param($e) if(($e.Category -match "Queued") -and ($e.RelatedDocumentIds -contains $serverTasksID))
        {
        #$True # This is optional and returns the entire event object.
        Write-Host "The account which :" $e.message ": Was :" $e.username
        }
    })

Does this look like it’s what you are after?

Let me know if you have any questions here or run into any issues.

Best regards,
Daniel

1 Like
(Mohamed HAJJI) #4

Hi @Daniel_Fischer
thanks for the script, yap it did help a lot !
Kind regards
Mohamed

(Daniel Fischer) #5

Hi Mohamed,

Thanks for the update here! I’m glad this helps.

Feel free to get in touch at any time if you have any further questions or run into any issues.

Best regards,
Daniel

(system) closed #6

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