Get Jenkins template name from Groovy Pipeline - jenkins

I have created many pipelines from a set of templates in my Jenkins. My question is simple. I need to retrieve from the Jenkins pipeline Groovy script that we have defined in our template precisely the name of the template so I can send it to an IP for verification.
I'm aware that we can retrieve many system variables from env and other predefined variables (https://myjenkinsmachine/pipeline-syntax/globals#env) but precisely i cannot find a way to retrieve to name of the template the pipeline is based on.
Any help? Thanks a lot.

Related

Generating Jenkins Jobs WIth JobDSL and a Template

I have a lot of jenkins jobs which are very similar. They all have the same input parameters and same build steps so i was wondering whether theres a way to generate these jobs through Job DSL and a template.
I would like to keep separate groovy files for each job which has all the parameters for the template (for e.g: github repo, env, etc). Job dsl will read through these parameter files and uses the template to generate new jenkins jobs.
Do you think this is possible, Ive looked everywhere for a solution but it doesnt seem like something like this exists

How to Send Gradle Parameters TO Jenkins?

I’ve seen many articles for sending Jenkins parameters to Gradle, which are passed as System variables, but have not come across doing the opposite. In my build.gradle file I have specified 2 parameters for a file name and version number. In order to pass this file name to the next job in the pipeline, I’d like to send the parameters to the next Jenkins job so it can make use of the file.
Is sending gradle params back to Jenkins possible using built in functionality??

how to use emailext-template in jenkins pipeline to get the template?

There is a good plugin, emailext-template. Basically, I do not have the access to Jenkins-server. It is not convenient to choose the option mentioned in emailext to create the email template.
I dont know how to use this emailext-template plugin to get the template in jenkins-pipeline. There is no guideline in emailext-template. Any documents?
// expected usage in jenkins-pipeline
template_str = emailext-template('template-id')
This can be done in the following way, In case you can deploy jenkins again (if it is done on the cloud), you could create and deploy your email template as part of jenkins installation and configuration.
In case you did not have access to the jenkins server even while deployment, you can just form the html template with the corresponding variables and then use them in the job configuration itself.
The below image shows how the template files are used in jenkins, Instead of the script tag as in the image, you can replace with your own html content so that jenkins will be able to send email with that content.

Jenkins: Pass environment variable to the job parameter

Since I have the same static rarely changed parameters used by several jobs I decided to put it somewhere in one place of my Jenkins and use it across jobs.
The first thought that came to my mind was to move my 'static data' to the environment variables and get it using Active choice reactive parameter plugin which allows running simple groovy scripts on the job parameters page.
Please note that I know how to get environment parameters in the pipeline, but I do really need to have this data on the build with parameters screen, e.g. once I clicked build with parameters - I need my groovy code inside Active choice reactive parameter was able to read this environment variable and display as a parameter to the user.
A simple example of this need:
The environment variable contains the list of servers, the job is going to perform deployment of the application to the selected server. In this case, I want to be able to write something like this in the groovy script section of Active choice reactive parameter:
return[${env.SERVERS_LIST}]
Unfortunately the example above doesn't work. I wasn't able to find any working solution for this yet.
Well, after a few more tries I finally found a solution.
Instead of trying to read the environment variable in the pipeline manner the simple
return [SERVERS_LIST]
works perfect

How to choose job name from Jenkinsfile when creating the pipeline from BlueOcean

When creating a job/pipeline from BlueOcean interface the pipeline name is set to repo-name. I have a requirement to change this default behavior. We need a specific pattern in these Jenkins job name (something like a team name prefix for each pipeline name and this prefix is missing in the repo name).
I am using declarative pipeline V2. I did a search here - https://jenkins.io/doc/book/pipeline/syntax/#options but seems no option to do so.
I am looking at any available option to be able to use my own defined name and not the repo-name by default. I found when you create a pipeline in jenkins BlueOcean and if a job already exist with the same repo name, it does allow me to override "display name". so is there a way to put job "display Name" in BlueOcean other than default.
Thanks in advance :)
Please let me know if any information is required.
seems no option available. jenkins BlueOcean is designed to be simple. https://issues.jenkins-ci.org/browse/JENKINS-61705

Resources