How do I get the name of the pipeline from inside the jenkinsfile
Since you are using the multibranch job, the env variable is returning the actual job name that it created out of the branch .i.e. _ .. So, without some mechanism to strip/sed out the branch name, i don't think there is an env variable for it in jenkins out-of-the-box.
@red888 pointed out the following answer that worked like magic for me. I am pointing it out in an actual answer because I almost missed it:
env.JOB_BASE_NAME
Credit to @red888 in the comment above. Send upvotes his/her way.
You can check http://YOUR-JENKINS-SERVER.com/pipeline-syntax/globals#env
and it'll get you
JOB_NAME
Name of the project of this build, such as "foo" or "foo/bar".
JOB_BASE_NAME
Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo".
For a jenkins organization project with multiple branches and PRs, the JOB_NAME
is actually YOUR_ORG_NAME/YOUR_REPO_NAME/YOUR_BRANCH_OR_PR_NAME
, e.g. my-org/my-repo/PR-23
, and the JOB_BASE_NAME
is just PR-23
. Just as Israel said, you can use env.JOB_NAME.tokenize('/') as String[]
to get what you want.
If you want more fancy scripts in Jenkins, Groovy can be a good reference.