Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the name of the pipeline from inside the jenkinsfile

Tags:

env.JOB_NAME Is the pipeline name suffixed with the branch name.

So env.JOB_NAME will be <jenkins_pipeline_name>_<my_branch>

How can I just get the pipeline name and store it in a var in the environment{} block at the top of my jenkinsfile to use through the file?

I don't want to resort to scripted pipeline just the declarative.

like image 839
red888 Avatar asked Aug 18 '17 00:08

red888


People also ask

What is the name of pipeline file in Jenkins?

The definition of a Jenkins Pipeline is typically written into a text file (called a Jenkinsfile ) which in turn is checked into a project's source control repository. For more information about Pipeline and what a Jenkinsfile is, refer to the respective Pipeline and Using a Jenkinsfile sections of the User Handbook.

How do I see the pipeline in Jenkins?

Step 4) Go to your Jenkins dashboard and create a view by clicking on the “+” button. Select the Build Pipeline View option and click OK. Step 5) Under Pipeline view configuration, locate Pipeline Flow. Under Pipeline flow, select the initial job to run.

How do I get a pipeline script in Jenkins?

To create a simple pipeline from the Jenkins interface, perform the following steps: Click New Item on your Jenkins home page, enter a name for your (pipeline) job, select Pipeline, and click OK. In the Script text area of the configuration screen, enter your pipeline syntax.

How do I get the full project name in Jenkins?

Open Jenkins, create a job, then In the 'Execute shell' > 'Command' textbox, write the above two, both will work. Job mentioned above is within the Jenkins, not environment variable outside jenkins.


1 Answers

@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.

like image 195
Jeff Diederiks Avatar answered Sep 30 '22 17:09

Jeff Diederiks