How do I create a view across folders in Jenkins? - jenkins

In our previous Jenkins setup we used a combination of the Build Monitor Plugin and the View Job Filters Plugin to create a screen showing our last 18 builds.
With our new setup we decided to break the builds into multiple folders, some of which are just simple folders, one is a dynamic folder pointing to Bitbucket. We would now like to re-create the same kind of view: show the 18 most recent builds across all of our builds.
If I just select the top folders in the configuration of the build monitor view, then no builds appear - no matter if I set the "Recurse in subfolders" option or not. I need to manually select individual jobs, which is not something we want to maintain in the long run.
If I use a regular expression match, then it includes jobs from other folders that are not selected.
There is also nothing I can find in the "Add Job Filter" menu that seems to allow me to filter jobs to come from within a selection of folders.
I can create multiple build monitor views, one for each folder - but that doesn't give me the last 18 builds over all.
Is there a way to create a build monitor with a number of most recent builds across multiple folders?

I figured out that you can use a regular expression to include jobs, assuming that all the jobs are contained in a single subfolder, my-jobs, you can do:
my-jobs/.*
to include only jobs within those folders.
Further, you can restrict this more by adding job filter matches which let you exclude other jobs if it starts including more jobs than you wanted.

For me on the latest version of Jenkins at time of writing (2.240), for the view to pick up jobs in subfolders, I had to tick Recurse in subfolders else the regular expressions would not match any jobs in folders.
Combined with Use a regular expression to include jobs into the view and a regular expression such as the one below, I was able to get the view to show jobs within a folder:
/MyFolder/.*
I suspect that if you wanted to include jobs from multiple folders, you could do so with a regular expression such as:
(/MyFolder/.*)|(OtherFolder/.*)

Related

Automatically find Jenkins jobs that refer to a given job (and vice versa)

There's a vast variety of ways for connecting Jenkins jobs to other jobs (e.g., triggering, copying artifacts, promotion criteria etc). Is there a way to (reliably) determine which Jenkins jobs refer to a given job X? (Or, conversely: which jobs are referenced by a given job X?)
I tried heuristics like grepping all config.xml files for job name X, but this is not reliable of course. E.g., that catches job names in text/comment sections, and it will miss references that are not stored in the job config.xml files (like settings for the promoted-builds plugin).
I'm not interested in checking for specific kinds of references (this is simple once you know the corresponding XML format or the internal connection on object level). I wonder if there's a way to check for any kind of reference between jobs in a generic way.
As background, there's several use cases where you may want to determine which jobs are "connected" in some way, e.g.:
Cleaning up your job inventory: you want to delete obsolete jobs, but before deleting, you want to be sure that no other job still depends on it.
Packaging a collection of jobs (including all its dependencies) for a customer
Updating references to some job X that has been replaced or moved to some different folder.
Can't you do something similar to this:
Get Jenkins upstream jobs
That way you can just see which jobs are triggered by upstream?
Similar for downstream:
List all downstreams project for a project in jenkins

How I can run single Jenkins job by previously defined rules

I'd like to get a hint how (which plugin) it is possible run SINGLE Jenkins job by the user chosen way. User MUST be able to choose the job he/she wants to run and choose the rule of execution:
E.g:
Create only jar files;
Create jars and send them over ssh
Create jars, generate documentation, etc...
I've found out a few plugins (Artifactory, Release plugin) but seems they don't support such logic.
I know that such thing can be implemented by creating several jobs, but this would require additional disk space.
Many Thanks!
In order to solve my issue, I've decided to create a few Jenkins jobs with the same custom workspace. So that, when a IT engineer runs any of these "connected" (which have the same workspace) jobs the workspace is updated (have a look at the CVS rules for your job) and that's why we avoid wasting of space.
Additionally, its (job) behaviour can be configured easily => the sets of rules (shell scripts, gradle, batch etc) and their sequence in order to achieve the desired result.
The last advantage, but not the least one, is that the security (access control) is still very easy to configure.
I think, that is the correct way.

Is it possible to have multi-config template in Jenkins?

I have a number of multi-config jobs and all have to run on the same machines, one after another.
For example:
Build on all platforms.
Do some automated testing.
Do some automated benchmarking.
These are all happening on the same machines, in that order, but they are different jobs.
The problem is that if I want to add another platform or remove one of them, I will have to do it for every single multi-config job. What I would like is to have a way of defining those platforms in one place and then have the jobs point to that template and run.
I am quite sure I'm not the first one to hit this problem and that there should be some plugin out there, but I haven't been able to find it.
So, is there any simple way of doing this?
We create temaplte jobs in jenkins which helps us to create all the set of jobs reqired for a platform, we just pass the platform / component name as input pareamter for the template job. We us the job copy plugin https://wiki.jenkins-ci.org/display/JENKINS/Jobcopy+Builder+plugin
But for a deleting the jobs we have another job where again the component name is the input parameter and we use something similar to the answer given here Is it possible to delete a hudson job programmatically via REST API?

Copying and Editing Jenkins Jobs

I have been using Jenkins for a couple of months now, and have been able to set up a simple CI system.
I currently have a build tab - that will build and deploy 25 different components successfully, based on building from an SVN trunk.
I'm now taking my first branch - some people will develop on the trunk and some will develop fixes on the branch.
I would now like to have CI up and running for both branch and trunk - so would create a second tab - with a repeat of the jobs from the first tab, but this time changing the SVN path to check out from the branch.
As I have rather a lot of jobs and the task is quite repetitive, is there an easy way to do this ? I'm hoping that each job tab might be a single xml that I can edit / rename to give me a second tab ?
Yes, each job is as single xml file, located under $JENKINS_HOME/jobs/$JOB_NAME/config.xml. However there are a number of places in the config.xml that reference it's location, so simply copy-pasting the actual file isn't the best option.
Jenkins UI itself has "copy job" function.
Click "New Item" where you want it
Select "Copy existing Item"
Specify the name of existing item to copy
Specify the name for the new job
Then go to configure the new job and change what you need.
Another tip: may not apply to your setup, but more often than not, there is a "unifying difference" between multiple similar jobs, most often a branch name, or project name, or similar. The value would be that only one that needs to change between otherwise identical jobs, however that changed value may appear several times within the job configuration.
I usually make a "choice" parameter, with a single choice, and put that different value there. The rest of the job references the choice param as a variable. So when I copy identical jobs, I just need to change that 1 value at the top of job configuration page. Everything else falls into place.

Jenkins - Keep workspace permanently and update; Build separate jenkins jobs within that workspace

I have a build area (BuildArea) checked in, which contains shared scripts and wrappers and whatnot that I use to build a project.
This is rarely updated.
Separately, I have various projects (Proj1, Proj2, Proj3...) under development which update regularly.
Standard flow is to checkout the latest source files from a project (e.g. Proj1), and then build the project in my build area (BuildArea).
The next day there's an update to Proj1 and also a Proj2, which I also want to build in my build area.
All these builds only read the files in BuildArea; no modifications are made except to create a unique results directory.
So, my questions are:
1. Can I create a Jenkins job that maintains a build area (BuildArea) and updates daily for example.
2. Can I then kick off independent Jenkins jobs that run within that build area and dump their results there?
The main reason I want to do this is that there are many projects run during the week and the build area is enormous, so checking out a local build area for each project is a big waste of resource.
Yes, this should be possible. Set your primary job with a custom workspace and have it store the files in a networked location, and then set up the scripts from your smaller jobs to access those files directly. We use clearcase and i had set up something similar with snapshot views. Your first job will just have the scm step, and your smaller jobs will only pull the files for your project.

Resources