Search for a module in all Jenkins jobs - jenkins

Is it somehow possible so search for a module within all Jenkins jobs?
Let's say there's the module common-messaging. It's built in Job 1 and Job 2.
When I search for the module name I want both jobs to be shown.

Jenkins store the jobs configuration on disk in XML files. So you can grep the file for whatever XML element is created by the plugin.
create a new job that just have that plugin enabled.
get the XML file: /ci/job/name_of_your_job/config.xml
look for an XML element that correspond to common-messaging, lets say common-messaging.plugin
Then if using a UNIX system:
grep common-messaging.plugin /var/lib/jenkins/jobs/*/config.xml
Windows must have a similar command.

If you have admin access to the server, install the Scriptler plugin (which gives you more easy access to the Groovy console), and fetch and run this shared Scriptler snippet: http://scriptlerweb.appspot.com/script/show/486001

Related

List all files in specific directory in repository in Jenkins

I would like to add parameter in Jenkins job that would discover files in specific folder and by ticking some of list elements let me choose only those I need. I have got main folder with two additional directories inside (/app and /tests) and from tests I would like list all files.
Do you have any ideas how to do that including 'list subversion list' ?
So I found the solution by my own. If you are curious then here it is:
- install Active Choices Reactive Parameter in jenkins
- install subversion on slave
- add Active Choices Reactive Parameter to jenkins job and write groovy script using 'svn ls path_to_repository'

Jenkins display multiple JMeter report(.jtl) in single graph

In Jenkins, I have configured multiple JMeter scripts using maven-jmeter-plugin in single job. After execution, each JMeter script is generating its own report file(.jtl) in results folder.
I have also configured the Performance plugin of Jenkins to display the report after JMeter script execution.
My problem is, the Performance plugin is showing different graph for each .jtl file.
Current Graph
I need to report to be shown in single graph.
Expected Graph
Is there any plugin available to achieve the same?
if no, how can I update the current plugin to achieve merged graph?
There is Merge Results plugin which can be used for combining/comparing results of up to 4 different JMeter tests.
You can install the plugin using JMeter Plugins Manager
Merge Results tool can also be used in command-line
Amend merge-results.properties (by default it's located in "bin" folder of your JMeter installation), make sure it contains these lines:
inputJtl1=TestResult_1.jtl
inputJtl2=TestResult_2.jtl
Execute Merge Results using JMeter Plugins Command Line Tool like:
JMeterPluginsCMD --tool Reporter --generate-csv CombinedResult.jtl --input-jtl merge-results.properties --plugin-type MergeResults
Configure Jenkins Performance Plugin to read CombinedResult.jtl file instead of your 2 files.

Loading Custom jar files in Jenkins without the Classpath Field

How can I load a custom jar file for my Jenkins Jobs DSL groovy scripts without the classpath field?
I've inherited a Jenkins instance. This Jenkins instance has an older version of the Jenkins Jobs DSL plugin. This version of the jobs plugin has a class path fields
By loading this jar file, my script (in the DSL Scripts) has additional symbols/classes it may import.
However, the latest versions of the Jenkins Jobs DSL have removed this class path field. The impression I get from the mailing list) is this was done for security reasons.
Without this option, is it possible to set a different class path (or include extra jar files in my Jenkins Jobs DSL groovy scripts without this field?
No, there isn't any direct option available. Following are the options available
Option 1: As Daniel has suggested (https://groups.google.com/forum/#!topic/job-dsl-plugin/lYgX3boW0Pk) , you can use the Script Security Plugin to add custom classpath and include the jar(s). The only overhead with this approach is, even if there is a minor difference in the jar, an approval would be required.
Option 2(Least Preferred, Last Option): If you are running Jenkins under a company network and if your confident on security, then you can consider to uncheck the Enable Security for Job DSL from Jenkins-> Configure Global Secutiry

Specify Owner when creating jobs from Jenkins CLI

I have a groovy script that runs the command jenkins-cli create-job and uses an xml template to create a new maven job. In the template, I attempt to specify the owner using the jenkins ownership plugin, but this information is ignored. It appears that jenkins uses the default setting and sets the owner to the creator, which in this case is jenkins and thereby deployman. I'd like to somehow get around this and assign the proper own either by passing it on the command line or telling jenkins to ignore that default setting that sets the owner to the creator. Does anyone know how to do this?
Note: I have inspected the xml file passed on the command line and the config xml file of the new project in jenkins and run a diff between them. The only difference the the owner set to the wrong person.
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
Read "Working with Credentials" section.
Also you can validate who is logged in with following jenkins cli command.
who-am-i : Reports your credential and permissions

Jenkins Job DSL - behaviour conditional on file contents

I have inherited a system which uses Jenkins Job DSL to build the jobs for all our projects, I have little experience with configuring Jenkins and none at all with Jenkins Job DSL, so please be gentle.
Some of these projects are Gradle projects. There is a function, createGradleJob() which creates the gradle job. In this function we build the task list for the job, as a string, based upon some features of the project. e.g. if it is being built from the master branch we append the 'publish' task. All of these conditional tasks are currently appended based upon the projects branch name, or the presence , or absence of certain files in the projects repo.
I would like to now add a new task into this task list conditional upon the contents of some of these files. Specifically if certain keywords are detected in the projects build.gradle file then certain tasks need to be appended to the task list.
So, is there a way in Jenkins Job DSL to check the contents of a file and use that as a conditional expression?
I have found that I can execute arbitrary shell commands using the shell function, so I thought I could just grep the file, but I can't locate the documentation for this function, so I'm not clear how I can able to access the output of the commands, so as to use them in a conditional expression.
I have found the textFinder function, but this appears to only allow you to fail (or mark as unstable) the build as a result of finding or failing to find, the text, not use the result as a conditional expression.
It sounds like you want to readFileFromWorkspace. It returns the contents of the file as a string. Simply read your file and parse the string as needed using the Groovy and/or Java string utils.
It's not quite clear from your question, but if you're talking about reading files out of the repo to be checked out by the job you're generating, this function won't help. But if the file is already somewhere in the workspace (i.e. it's one of the files checked out by the seed job), you'll be fine.
The shell command you found adds an "Execute Shell Script" build step to the job being generated. It doesn't actually execute the script there and then, it just copies the contents of the parameter verbatim into the build step ready to be executed when Jenkins runs the job.
For your continued sanity, here is a link to the Job DSL API Documentation

Resources