Jenkins manual trigger, how to display configuration variables from SVN on page - jenkins

I have all my test environment configurations stored in SVN in .properties files. I also have a Jenkins job that can deploy my artifacts to a specific test environment with delivery/build pipeline manual trigger. However, this can create a sense of uncertainty because I am never quite sure what configurations I deploy to the test environment as Jenkins does not automatically show them to you.
I noticed Jenkins offers parameterized builds, and offers you a page which lets you parameterize some values e.g. using some drop-down before triggering the build. My question is , would it be possible to have Jenkins display all the key/value pairs I have defined in my .properties file, and even let me change them? This way I could always review/edit my environment properties before actually making the deployment. Ofcourse, if I make changes then I need to remember to add them to SVN too... Thanks for your input!

Related

How to copy parameters from one pipeline to another without copying entire pipeline?

On our team, only few people have Jenkins access to perform admin operations as it is Production Jenkins server which developers continuously use for builds.
Sometimes I have to enhance any pipeline or fix issues of pipeline. For that admin has created one pipeline for me so I can add code there and test it. I am suppose to use only that pipeline to test anything.
But I test different pipelines, each pipelines has different parameters list. In this case, I've to add parameters one by one and copying all details of that parameter like Groovy Script, default value etc. which takes lot of time.
Is there any way/plugin using which we can simply copy only parameters from one pipeline to other?
I think you should know each job has a config.xml which represents the job configuration. You can get it by <job_url>/config.xml.
Get the config.xml of the job you want to debug, then extract the xml block for job parameters from the config.xml
Prepare an empty structure config.xml, inject the job parameters' xml block into the empty config.xml
Call Jenkins Rest API to update/save the config.xml to your debug job, then your debug job has target job's params.
You can write a script to implements above 3 steps.

How to update a Jenkins Properties Global Environment Variable from within a pipeline stage in Jenkinsfile

Wanting to update a ".env" properties value, so that the next execution has a new value.
loggingUtils.info("${env.testVar}")
env.testVar = "cat"
loggingUtils.info("${env.testVar}")
Currently what happens is if I configure the "env.testVar" to have a value of "dog" from within jenkins the print statements will be:
dog
cat
but the next time I execute I want it to be
cat
cat
However, it is always just
dog
cat
Is there a way to achieve setting the environment variables so that future builds will have the new variable? I would prefer to do this without a plugin if possible
Builds (can be thought of as "instances of executions") in Jenkins are independent of each other.
If you are trying to tie builds together by transmuting information across builds I would encourage you to think about what you are really trying to do and suggest you might not doing Continuous Integration properly.
Each time you execute a build it starts from scratch. Continuous Integration always starts with what's in source control. Nothing derived should be committed to source control.
I would suggest environment configuration should normally by stored in config files in source control and applied as appropriate via parameters to a build. (i.e what environment do I want to deploy a given build to?).

Can a single seed job process DSLs from multiple repos?

I recently managed to convert several manually-created jobs to DSL scripts (inlined into temporary 'seed' jobs), and was pleasantly surprised how straightforward it was. Now I'd like to get rid of the multiple seed jobs and try to structure things more cleanly.
To that end, I created a new jenkins-ci repo and committed all the Groovy DSL scripts to it. Then I created a job-generator Jenkins job that pulls from the jenkins-ci repo and has a single Process Job DSLs step. This step has the Look on Filesystem box ticked, with the DSL Scripts field set to jobs/*.groovy. With global push notifications already in place, this works more-or-less as intended: if I make a change to the jenkins-ci repo, the job-generator job automatically runs and regenerates all the jobs—awesome!
What I don't like about this solution is that it has poor locality of reference: the DSL scripts for the job live in a completely separate repository from the code. What I'd really like is to keep the job DSL scripts in each individual code repository, in a jenkins subfolder, and have a single seed job that processes them all. That way, changes to CI setup could be code-reviewed right alongside the code. To me, that just feels like an ideal setup.
Unfortunately, I don't have a clear idea about how to make this happen. If I could figure out a way to make the seed job watch multiple repos, such that a commit to any one of them would trigger it, perhaps I could inject another build step before the Process Job DSLs step and (somehow) script my way to victory, but... I'm unsure how to even get to that point. (I certainly don't want to do full clones of each repo in the generator job just to pull in the DSL scripts!)
I suspect I'm not the first person to wish they could put the Job DSL scripts alongside the code, though perhaps I'm over-estimating the benefits. Any advice on this topic would be much appreciated—thanks!
Unfortunately there is no direct way of solving this. Several feature requests have been opened (JENKINS-33275, JENKINS-37220), but AFAIK no one is working on any of them.
As a workaround you can use the Pipeline Multibranch Plugin and create a multibranch project for each of your repositories. You must then add a simple Jenkinsfile to each repo/branch and use the Jenkinsfile to execute your Job DSL scripts. See Use Job DSL in Pipeline scripts for details. This would require minimal coding, but I think each repo must be cloned for this to work because the Job DSL files must be available on the file system.
You can use Job DSL to create the multibranch jobs, see multibranchPipelineJob in the API viewer. This would be your "root" seed job.
If your repos are hosted on GitHub, you can also checkout the GitHub Organization Folder Plugin. With that plugin you must only create one job for each organization instead of multiple multibranch jobs.

How to instruct Jenkins to look for email template in user defined path (OTHER THAN $JENKINS_HOME/email-templates)

I have groovy email template(for Selenium Robot framework test execution) for Jenkins. Jenkins master is controlled by a remote team. So for placing this template in $JENKINS_HOME/email-templates, we need to raise a ticket and wait from 2 to 3 days. Also we expect, there might be changes required in template. So we are planning to put our templates inside our source code repository (GIT). so in the Jenkins test job, we checkout the test script together with email templates.
How to instruct Jenkins to look for the template in workspace folder instead of $JENKINS_HOME/email-templates in Jenkins Master
Sadly it seems you would need to modify the email-ext plugin as the search path is hardcoded into it.
You can see it here, check the occurrence on line 69 in file src/main/java/hudson/plugins/emailext/EmailExtTemplateAction.java
Changing it to another path would be trivial, however adding multiple locations you'd probably have to put some work in.
Edit: I wonder if it would be possible to put the wanted stuff into some txt file as a build step, and then load it into the mail content via some template configuration. If you have access to the job configuration this might be worth checking.
You can copy the template into the build workspace (e.g. with SCM step), and then email-ext can reach it:
${SCRIPT, template="${WORKSPACE}/foo.template"}

Generic jenkins jobs

I wonder, if it is possible to create generic parametric jobs ready to copy where the only post copy action is to redefine its parameters.
During my investigation I find out that:
- I can use parameters in svn path definition
- I can define the flow of builds using *Build Flow Plugin*
However I cannot force Jenkins to use parameters inside job names definition for promotion process. Is any way to achieve that?
Since I create sometimes branches from master I would like to copy the whole configuration of jobs but only one difference most times is that in the job name definition I replace master with branch name.
Why it not possible to use a parameter as the branch name?
Then when you start to build the job, you can input the parameters based on the branch you want to build.
Or find some way to get the branch info and inject it.
For example, we have one common job, which will monitor maybe 20 projects, if any of those job was merged into git, our gerrit trigger plugin will start to work, and all of job name, and branch is got dynamically from parameters.
Hope this works for you.

Resources