Skip to content

Instantly share code, notes, and snippets.

@KenDUemura
Created September 29, 2016 23:31
Show Gist options
  • Save KenDUemura/48856cc1e9cd1aedf041b602ce89bf15 to your computer and use it in GitHub Desktop.
Save KenDUemura/48856cc1e9cd1aedf041b602ce89bf15 to your computer and use it in GitHub Desktop.
Jenkins Pipeline, Get current Job's Folder Name
def getFolderName() {
def array = pwd().split("/")
return array[array.length - 2];
}
node(){
stage 'Get Folder Name'
def foldername = getFolderName()
print "${foldername}"
}
@Neded8
Copy link

Neded8 commented Oct 6, 2021

That's what I've looked for. Thank you!

@a1k0u
Copy link

a1k0u commented Oct 13, 2023

Great! You can also check the env variables that Jenkins offers you
https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables

For example env.JOB_NAME prints folder name and job name

@gzarct
Copy link

gzarct commented Feb 29, 2024

Great! You can also check the env variables that Jenkins offers you https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables

For example env.JOB_NAME prints folder name and job name

This is what I am looking for, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment