The concern is documenting the creation of an aliased function in powershell that utilizes the powers of nomad cli to receive the allocation logs with a simple command n $jobId — we have a 1:1 mapping of jobs to allocations in my environment.

1. requirements

  • ✅ nomad authentication
  • ✅ nomad CLI up and running

2. job hierarchy

  • hierarchy: job → task group → allocation → task

3. what is an alloc ?

An Allocation is a mapping between a 1) TASK GROUP in a JOB and 2) a CLIENT NODE A single job may have hundreds or thousands of task groups, meaning an equivalent number of allocations must exist to map the work to client machines. Allocations are created by the Nomad servers as part of scheduling decisions made during an evaluation.

— from The Architecture pf Nomad

4. get job status

  • issue here with windowd
  • the GUID is randomly generated
▶ nomad job status 8947d8c2-32d6-4e0e-a308-0e0c3539f6af
ID            = 8947d8c2-32d6-4e0e-a308-0e0c3539f6af
Name          = foo/bar
Submit Date   = 2020-10-29T14:35:38Z
Type          = batch
Priority      = 50
Datacenters   =
Namespace     = default
Status        = dead
Periodic      = false
Parameterized = false

Task Group        Queued  Starting  Running  Failed  Complete  Lost
deployment-group  0       0         0        0       1         0

ID        Node ID   Task Group        Version  Desired  Status    Created    Modified
8947d8c2  1cdd3e02  deployment-group  0        run      complete  4m56s ago  3m2s ago

5. powershell implementation get logs from the job id

  • in the $profile of powershell
function get-nomadLogs ($jobId) { $nomadLogs = nomad alloc logs -job $jobId | oh -Paging }
Set-Alias n get-nomadLogs
  • call with jobID → this gets you logs in the terminal
n 8947d8c2-32d6-4e0e-a308-0e0c3539f6af
  • result


6. issues with out-file

  • it is possible to use out-host but not possible to use out-file properly
  • don’t know why
  • the output is full of tofu characters
  • I’ve tried different fonts (Google Noto, too) but no success there


7. sources