GlennH
GlennH

Reputation: 105

Cloudbees Jenkins Folders Plugin: Folder Name as Enviroment Variable

Is the Folder Name available as an environment variable similar to JOB_NAME?

For a folder; JOB_NAME contains the full path including parent folders. I want the immediate parent folder as an environment variable.

Upvotes: 0

Views: 4274

Answers (3)

Andre Francois
Andre Francois

Reputation: 11

I used:

FOLDER_NAME=${JOB_NAME%/*}
STAGE=${JOB_NAME##*/}

See http://www.tldp.org/LDP/abs/html/parameter-substitution.html

Upvotes: 1

BrianV
BrianV

Reputation: 1496

Using the suggestion of $(basename $(dirname $JOB_NAME)) combined with the Environment Script Plugin, you should be able to set such an environment variable by selecting Generate environment variables from script and then providing the Script Content of:

echo FOLDER_NAME=$(basename $(dirname $JOB_NAME))

Upvotes: 0

Jesse Glick
Jesse Glick

Reputation: 25461

No such variable exists, but $(basename $(dirname $JOB_NAME)) would give you what you are asking for.

Upvotes: 0

Related Questions