Jenkins: Log Parser Plugin configuration - jenkins

i'm quite new in Jenkins. I would like to use the log parser plugin to parse the console output of jenkins.
Like the documentation explains I have to add a file, which is containing my parsing rules.
So there is my question:
How do i upload files to jenkins? Do they need to be located in the projects workspace? My workspace is connected with a git repository. So i have to commit that file?
For example the file /tmp/rules.txt how do i get the rules.txt in the /tmp/ folder (and which folder is it, the workspace/tmp or the /tmp/ of the server itself)?
Do I have to transfer it via ssh?
Thanks for help!

This file dont have to be in the projects workspace. You don't have to uploat it on Git. Just create file somewhere on the computer, where jenkins runs.
You must change Global Configuration (/jenkins/configure). There is a section "Console Output Parsing". In description you can put, for example, : "Rules1" and in "Parsing Rules File" - path. Then in each job you want to use this rules configure Post-build Actions -> Console output (build log) parsing.

Related

Jenkins/Groovy move variables out to a config file

I've been asked to move some variable from a Groovy script out into a configuration file. I'm fine using something like :-
readFile('../xx-software.cfg').split('\n').each { fileName ->
sh "wget ${theURL}${fileName}"
}
However, even though I have added xx-software.cfg into the same directory as my Groovy script it does become available for use within that groovy script.
I hope this makes sense!?
How can I move my variables out into a config file to make it easier for the application support team to make future edits without changing the code?
There are a few approaches you could use.
Firstly, file format for the configuration and how to read the data into variables. You could use Java Properties format, YAML or JSON and these are all handled by the Pipeline Utility Steps plugin with steps here. You can read the file with these steps:
readProperties
readYaml
readJSON
Next problem, how to get the file available to your pipeline so it can be read from the workspace using these steps. Possibilities are:
In source control with your pipeline code. It can be fetched with the pipeline.
In a separate source control for configuration, your pipeline will need a step to fetch it.
Use the Jenkins Config File Provider plugin. It has a step to provide a config file managed in Jenkins.
Provide it as a Custom Tool zipped archive from a binary server like Artifactory. You can use custom tool definition pipeline steps to make this available to the pipeline.
The Config File Provider option might provide any easy way to have a file that can be updated, but there won't be any version control of it.

How to pass job-specific files to Jenkins as part of job configuration?

I have a jenkins job that pulls source code from GitHub public repo. I need to pass some files such as instance-specific configuration files containing secrets to the job and merge with source code prior to running build because these files are obviously inappropriate to be put in public SCM. The Jenkins instance is a multi-tenanted shared service.
The config files don't change often so I don't want to implement using file parameter which forces user manually input the file on every run. Another reason file parameter doesn't work is some builds are triggered automatically by SCM.
I don't want to use Config File Provider Plugin either, because the plugin requires jenkins admin access but I want users with job-level privileges manage the files themselves.
Ideally the uploaded files are saved alongside with job config.xml instead of in workspace, because I would like to delete workspace after each build. I can write scripts to copy the files from job config folder to workspace.
Are there any solutions available? Thanks.
If the "special" files are being placed in a folder with say some access privileges to it, couldn't you either run a Pre-SCM-Buildstep to move the files with shell commands, or introduce a regular build step (i.e. after the SCM stuff and before the other build steps) that would also use shell commands to move files?

change jenkins workspace and attach file with email using jenkins email-ext plugin

I am new to jenkins and i want to add my test report with the email attachment.
I am using
Email-ext
plugin to send email. Email is sent successfully but the attached file is not sent.
My test report generates in eclipse porject workspace inside and path is
E:\eclipse_environment\workspace\smautomation_jenkin\assets\chromeTestReport\
how i can attache my test file with email using this plug-in?
I am using mac and my solution works for mac.But i think the concept will be same for all os.
Actually, jenkin attach file from its workspace automatically. For this no expression is not required. For example, in my mac, jenkins workspace is
/users/dev/.jenkins/workspace
and i keep a file here named
report.txt.
And in "attachment" of email-ext plugin, just write
report.txt
no need to write any other thing. jenkins will go to its workspace and check "report.txt" exist or not. if exist, it send it as attachement.
Now question about the jenkins workspace.
Actually jenkins has its own workspace. You may need another workspace. To check jenkins workspace, go like this:
jenkins > manage jenkins > configure system.
Now at top u will see
Home directory
and theres an
Advanced
option. Click on it and u will see
Workspace Root Directory: and its value is
${ITEM_ROOTDIR}/workspace
ITEM_ROOTDIR is where .jenkins exist. For me this is
/users/dev/.jenkins
Actually u can see this at the first line:
Home directory -- ur ITEM_ROOTDIR is shown in this line.
now go to ${ITEM_ROOTDIR}/ and u will see a folder name workspace.
Now if u keep any file in this workspace, jenkin will send this file as attachement. Obviously u have to mention it in email-ext plugin "attachment" section.
Now if u want to change ur workspace, change ur
Workspace Root Directory:
like this
${ITEM_ROOTDIR}/jobs/test/workspace
it depends on you.Change according to ur wish.
the most important thing is, if u change ur workspce from
jenkins > manage jenkins > configure system > Advanced option under Home directory
this will be ur default workspace.
If u want to make a specific workspace for only
one project
than u have to follow another procedure.
Just create a maven job (project). Than enter into the project,
//click on configure, now click on "Advanced" option under "Build"
//For free style project, this is in "Advanced project option"
There, u will see
Use custom workspace
check this option, and give ur needed workspace. For me i give like this:
/users/dev/workspace/test1/
and this is
the workspace only for this project.
Now u can send file from here as an attachement.
one most important thing is u must restart jenkins server
to set the new workspace to ur job.
Actually u can copy files into jenkins workspace from another directory using cp command in
Execute shell option.
Now just give the file name in attachement of email-ext plugin and jenkins will send this file as attachment with ur email.
cheers.........
This method worked for me, to include html file in jenkins workspace to a mail body.
jenkins -> configuration -> Editable Email Notification
Content Type : HTML(text/html)
Default Content: ${FILE,path="build/reports/tests/test/index.html"}
Don't start file path with "/"

Jenkins: Log parser Plugin Error: Cannot parse log: Can't read parsing rules file

i put my parsing rules file in:
/var/lib/jenkins/jobs/Wireshark/parsing_rules.txt
in the jenkins configuration, where i have to set the path to my parsing file, i set the same path. But the Plugin can not find the file. It is only returning this error:
log-parser plugin ERROR: Cannot parse log: Can't read parsing rules file: /var/lib/jenkins/jobs/Wireshark/parsing_rules.txt
The content of the file is:
warn /| Failure/
ok /| Ok/
Can someone help me solving this error?
TL:DR:
Jenkins log parser files must be placed on the master, not slaves.
You are placing the parsing log rules file in the jobs folder:
/var/lib/jenkins/jobs/Wireshark/parsing_rules.txt
Are you expecting Jenkins to find it on the slave?
Jenkins looks for the file at the specifed path on the master not the slave, because the job's log parsing is performed on the master, not the slave.
You may define multiple parsers so you can have different parsers for different jobs.
You add each parser to the Configure System page, and in the job configuration, select the log parser you wish to parse your console log.
I faced this problem too, #ablarg helped me partially by showing "directions" for solution, but I will expand answer for Jenkins beginners like me and those who were not given infrastructure road-map =)
First you need to know on which server and in which directory you have a master and nodes.
1. Go to Jenkins settings - Nodes
https://your_jenkins_url/computer/
This will display all nodes and the master, find your job to understand on which server (IP) located workspace directory, and on which server (IP) is the JENKINS_HOME directory.
Now you need to check logs for node or master to understand on which server you can find job workspace directory or the directory for the global settings.
https://your_jenkins_url/computer/your_node_name/log
You will see the IP address of the server:
Inbound agent connected from 192.168.1.1
2. Now you need to know the path of the directory JENKINS_HOME and WORKSPACE job.
Go to:
https://your_jenkins_url/systemInfo
And search for "JENKINS_HOME"
The default is:
/var/lib/jenkins
This is the directory where you need to put the log parser configuration file for the Global Setup.
To define the workspace directory of the job you can simply specify in the "Console output (build log)" - "Use project rule" the name of the config file and when you start the job the path will be displayed in "Console Output (parsed)".
For example:
java.nio.file.NoSuchFileException: /var/lib/jenkins/jobs/your_project_folder/jobs/your_node_name/jobs/your_job_name/workspace/your_file
Now when you know on which server the node is located, you can put the log configuration file to the path shown in "Console Output (parsed)" output.
P.S.
Don't forget to set Chown of the user you have Jenkins running on this server for your log parser configuration file
Also you don't have to specify full path for "Use project rule", just file name.
I had the same problem, but under windows. After restarting Jenkins, it works.

Hudson/Jenkins PMD Configuration

I am new to Jenkins and just started configuring it. This is what i have done till now:
Installed and configured Jenkins to display the home page. Added PMD plugin.
Set the HUDSON_HOME to a specific directory > C:\Work\Jenkins
Configured a test build to run a simple do-nothing ant script. It runs successfully
Written an independent pmdbuild.xml to run checks on a set of files in C:\myview (I am using clearcase). This xml also copies the output pmd_results.xml to the workspace directory in $HUDSON_HOME/[job-name]/workspace
Now I added the pmdbuild.xml as a step in my primary build. So my build has 2 steps:
a. Run a simple script, do-nothing.
b. Run pmdbuild.xml which generate pmd_results.xml and place it in $HUDSON_HOME/[job-name]/workspace (HARD-CODED as Jenkins PMD plugin expects the file there)
Jenkins picks up the pmd_results.xml automatically with the plugin and displays warnings and everything.
Now the problem:
If I click on a filename in the PMD results, it gives a filenotfound exception as it is looking for the source file in $HUDSON_HOME/[job-name]/workspace.
My java code files are placed in C:\myview (a clearcase snapshot view)
My question is, do I need all my code files to be present inside $HUDSON_HOME/[job-name]/workspace ?? Meaning can't I tell Jenkins to look for the PMD input files in C:\myview or any other directory instead of $HUDSON_HOME/[job-name]/workspace ??
Sorry for the extremely long description.
Jenkins expects that all the code is in the workspace. Usually Jenkins is used to check out a copy of the code into the workspace, and then runs all build steps on the Sources in the Workspace.
Might seem restraining at first, but it saves you a lot of trouble if you need to move Jenkins to another server, or create a slave instance.
So I would suggest you let Jenkins check out your code (there should be a clearcase plugin) into the workspace, and run the analysis on the checked out code.
If there are compelling reasons why your code has to stay where it is (C:\myview in your case) you can still set the workspace of your build to that directory (find this in the job configuration page, you need to click on the 'extended' button to see the option).

Resources