Product: PowerShell Universal
Version: 5.3.2
I’m in the process of moving some scripts from Jenkins into PSU that run on a schedule, some of them run very often but don’t necessarily do anything so to avoid flooding the job list I want to prune those that aren’t actually performing any actions… in Jenkins I used a plugin that would delete runs based on a regex in the script output. In PSU I’ve implemented the following snippet in the bottom of my script:
if ($actionCount -eq 0 -and $UAJob.Schedule)
{
# Archieve job
$jobId = $UAJob.Id
$apiToken = Get-PSUAppToken -Identity "JobArchiver" -Integrated
Write-Host "Archiving job: $jobId .."
$response = Invoke-RestMethod -Uri "https://psu/api/v1/job/archive/$jobId" -Method "DELETE" -Headers @{
Authorization="Bearer $($apiToken.Token)"
}
}
It works but it’s a bit much to have to put in every script, so I have a couple of questions.
- Is there a better way of achieving what I want or would it be possible to add something to PSU so a script can mark its own job to be archived on completion?
- How do I limit the permissions of the app token identity, currently I have it set to Operator but I’m unsure how to only give access to archive jobs. The documentation mentions permissions like “automation/*” but I’ve only been able to find a couple of spefic “sub permissions” like read and execute.