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.
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.
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.
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.
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.
@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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With