Runbook triggering user?

Hi, I’m trying to output the username of who triggered a runbook in a Powershell script, on Octopus 2020.04.

I’m trying to use $OctopusParameters[‘Octopus.Account.Username’] but this appears to be blank in runbooks, but set for the project?

Here’s the script:

$username = $OctopusParameters['Octopus.Account.Username']
$hostname = $OctopusParameters['Octopus.Machine.Name']
$link = "https://octopus" + $OctopusParameters["Octopus.Web.RunbookSnapshotLink"]

$payload = @{
	channel = $OctopusParameters['slack_channel'];
	attachments = @(
		@{
		color = "good";
		fields = @(
			@{
			title = "Production config updated";
			value = "$username updated configuration on $hostname, see $link";
			});
		};
	);
}

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
Invoke-RestMethod -Method POST -Proxy $proxy -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['slack_webhook_url']  -ContentType 'application/json'

The output of this is " updated configuration on , see https://octopus/app#/Spaces…"

Thanks

Hi @oliver.r,

Thank you for contacting Octopus Support.

After trying this in my local test environment, I was able to get this to work by making the following change:
$username = $OctopusParameters["Octopus.Deployment.CreatedBy.DisplayName"]

Let me know if that works on your end as well.

Regards,
Donny

Works fine, thank you.

1 Like

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