diff --git a/.changelog/12603.txt b/.changelog/12603.txt new file mode 100644 index 000000000000..5da2df476f91 --- /dev/null +++ b/.changelog/12603.txt @@ -0,0 +1,3 @@ +```release-note:improvement +client: Added `NOMAD_SHORT_ALLOC_ID` allocation env var +``` diff --git a/client/taskenv/env.go b/client/taskenv/env.go index eaed60567a29..d40b52ab95c4 100644 --- a/client/taskenv/env.go +++ b/client/taskenv/env.go @@ -47,6 +47,10 @@ const ( // AllocID is the environment variable for passing the allocation ID. AllocID = "NOMAD_ALLOC_ID" + // ShortAllocID is the environment variable for passing the short version + // of the allocation ID. + ShortAllocID = "NOMAD_SHORT_ALLOC_ID" + // AllocName is the environment variable for passing the allocation name. AllocName = "NOMAD_ALLOC_NAME" @@ -505,6 +509,7 @@ func (b *Builder) buildEnv(allocDir, localDir, secretsDir string, // Add the task metadata if b.allocId != "" { envMap[AllocID] = b.allocId + envMap[ShortAllocID] = b.allocId[:8] } if b.allocName != "" { envMap[AllocName] = b.allocName diff --git a/client/taskenv/env_test.go b/client/taskenv/env_test.go index 5d9bf75e09e9..b149efdbd007 100644 --- a/client/taskenv/env_test.go +++ b/client/taskenv/env_test.go @@ -238,6 +238,7 @@ func TestEnvironment_AsList(t *testing.T) { "NOMAD_JOB_NAME=my-job", fmt.Sprintf("NOMAD_JOB_PARENT_ID=%s", a.Job.ParentID), fmt.Sprintf("NOMAD_ALLOC_ID=%s", a.ID), + fmt.Sprintf("NOMAD_SHORT_ALLOC_ID=%s", a.ID[:8]), "NOMAD_ALLOC_INDEX=0", } sort.Strings(act) @@ -404,6 +405,7 @@ func TestEnvironment_AllValues(t *testing.T) { "NOMAD_JOB_NAME": "my-job", "NOMAD_JOB_PARENT_ID": a.Job.ParentID, "NOMAD_ALLOC_ID": a.ID, + "NOMAD_SHORT_ALLOC_ID": a.ID[:8], "NOMAD_ALLOC_INDEX": "0", "NOMAD_PORT_connect_proxy_testconnect": "9999", "NOMAD_HOST_PORT_connect_proxy_testconnect": "9999", diff --git a/website/content/partials/envvars.mdx b/website/content/partials/envvars.mdx index 9edca49a950a..ef290c131beb 100644 --- a/website/content/partials/envvars.mdx +++ b/website/content/partials/envvars.mdx @@ -69,6 +69,12 @@
NOMAD_SHORT_ALLOC_ID
+ NOMAD_ALLOC_NAME
@@ -166,7 +172,7 @@