jenkins pipeline warnings graph - jenkins

I started to migrate some jobs in jenkins to pipeline execution.
Is there any chance to see the warnings graph in multi branch pipeline jobs? Within my older projects I can configure the graphs with "Configure the trend graph" option. These option will crash in the pipeline syntax tool.
Is there any option to make the graph visible?
I have in my Jenkinsfile:
stage ('Warnings gcc') {
step([$class: 'WarningsPublisher', canComputeNew: false, canResolveRelativePaths: false, defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', messagesPattern: '', parserConfigurations: [[parserName: 'GNU Make + GNU C Compiler (gcc)', pattern: 'error_and_warnings.txt']], unHealthy: ''])
}
stage ('Warnings clang') {
step([$class: 'WarningsPublisher', canComputeNew: false, canResolveRelativePaths: false, defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', messagesPattern: '', parserConfigurations: [[parserName: 'Clang (LLVM based)', pattern: 'error_and_warnings_clang.txt']], unHealthy: ''])
}
The reports will be generated but no graph is displayed.
UPDATE: Now it still did not work but it is also impossible to use the snipped generator for the warnings plugin.
Entering a file name in the snipped generator for the warning plugin results in a java null pointer exception:
javax.servlet.ServletException: java.lang.NullPointerException
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:796)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
at org.kohsuke.stapler.MetaClass$5.doDispatch(MetaClass.java:236)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
at org.kohsuke.stapler.MetaClass$10.dispatch(MetaClass.java:362)
some more lines follows ...
Mentioned in the revision log for the warnings plugin V 4.56:
Fixed deactivation of trend graphs (using the analysis collector plug-in)
But I use 4.57 and it still did not display any graph!
I posted the problem also to jenkins user list (no feedback for weeks) and also added bug report and bug report
Can anyone reproduce the problem or is the multi-branch pipeline simply still broken at all? Seems to be that there are not so much users for this plugin...

These issues have been resolved with the latest versions of both Jenkins, the pipelines plugin[s], and the plugins you have mentioned above.
Additionally, the bugs you specifically reported have been resolved:
[FIXED JENKINS-39553] Make GitHub plugin BuildableItem aware (#153)
[FIXED JENKINS-39532] Do not access the workspace for pipelines
Update your Jenkins instance and all of your plugins (some of them have interdependencies on others) and after the suggested restart you should be able to display the graph successfully.

Related

Jenkinsfile Trigger a job from quay.io trigger plugin

I am attempting to move from a Freestyle Project to a multibranch pipeline build. I would like my Jenkinsfile to trigger when a new container has been pushed to my Quay.io repository. In the Freestyle Project I'm able to accomplish this with the Quay.io Trigger Plugin.
Moving to the Multibranch build pipeline I've found this post, that describes how to trigger on a dockerhub trigger. I've also used the Jenkins Pipeline Syntax "wizard" to generate the code to add to my Jenkinsfile:
properties([[$class: 'ScannerJobProperty', doNotScan: false], [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false], [$class: 'ThrottleJobProperty', categories: [], limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0, maxConcurrentTotal: 0, paramsToUseForLimit: '', throttleEnabled: false, throttleOption: 'project'], pipelineTriggers([[$class: 'QuayIoTrigger', repositories: ['hostedsparkbots/janitorbot-timer', 'hostedsparkbots/janitorbot', 'hostedsparkbots/sparky']]])])
In the above case when I do a scan of my github repository I get a wall of backtraces from the jenkins console:
java.lang.IllegalArgumentException: java.lang.ClassCastException#712ddbf9
at sun.reflect.GeneratedMethodAccessor4447.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jenkinsci.plugins.structs.describable.Setter$1.set(Setter.java:33)
at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:338)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:261)
Caused: java.lang.IllegalArgumentException: Could not instantiate {repositories=[hostedsparkbots/janitorbot-timer, hostedsparkbots/janitorbot, hostedsparkbots/sparky]} for QuayIoTrigger(repositories?: String[])
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:264)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:380)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:461)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:365)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:318)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:259)
Caused: java.lang.IllegalArgumentException: Could not instantiate {triggers=[{$class=QuayIoTrigger, repositories=
Does anybody actually have this working in a Jenkinsfile?
The answer:
If you cast the collection of repositories as a java.util.Set in the Jenkinsfile, this works as expected. Using your list above, you'd want to do this:
#!groovy
#import java.util.Set // this may not be required?
properties([
pipelineTriggers([[
$class: 'QuayIoTrigger',
repositories: (['hostedsparkbots/janitorbot-timer',
'hostedsparkbots/janitorbot',
'hostedsparkbots/sparky'] as Set)
]])
])
The background:
I had been struggling to figure this out myself, but ultimately dug through the source code in the Quay.io Trigger Plugin. The current plugin isn't designed with Jenkins Pipeline in mind, so it uses a Set in the constructor for the repository collection.
This is where the cast exception is occurring, as Groovy is treating the list of strings as an array, an not able automatically cast this into a Set.
By explicitly creating the list of repositories as a Set, the plugin is configurable in the Jenkinsfile.
Hope this helps!

Job DSL script fails on generating job with allure plugin for reports

I have some groovy script for generating jenkins jobs, which worked great.
But after reinstallation of jenkins this script throws exception.
problem part of script is:
publishers {
allure(['path-to/reports'])
}
And error is:
Processing DSL script seed.groovy
ERROR: (JobBuilder.groovy, line 55) No signature of method:
javaposse.jobdsl.dsl.helpers.publisher.PublisherContext.allure() is
applicable for argument types: (java.util.ArrayList) values:
[[PyUIAutotest/reports]]
Possible solutions: mailer(java.lang.String),
use([Ljava.lang.Object;), asType(java.lang.Class)
Finished: FAILURE
It fails on wrong signature of method, but it is correct, and i don't know what is wrong.
example of script available on wiki dock. and javadoc for allure() method
Jenkins ver. 2.46.2; Job DSL ver. 1.63, Allure-Jenkins-Plugin ver. 2.15
weird thing in that, i have another server with same plugin versions, and it works fine
Instead of
publishers {
allure(['path-to/reports'])
}
use this syntax (which you can also generate using Jenkins pipeline-syntax generator):
allure([includeProperties: false, jdk: '', properties: [], reportBuildPolicy: 'ALWAYS', results: [[path: 'path-to/reports']]])
You might find my answer here useful: https://stackoverflow.com/a/71082002/1169433
In short, you may need to add the allure-jenkins-plugin in your build dependencies.

Jenkins master throwing java.io.IOException when running pipeline in swarm client

Im trying to run a pipeline job in an agent which is using swarm client. The job runs fine but im getting a lot of error messages in the log like below:
Cannot contact tst_db2: java.io.IOException: Remote call on Channel to /XX.XX.XX.XXX failed
(actual IP address replaced with XX)
In my observation the master is throwing this errors while waiting for the script that is running in the client. Again, the pipeline job run perfectly except that im getting this error on the pipeline logs.
Below is my pipeline script:
pipeline {
agent none
stages {
stage('Recreate DB') {
agent { label 'tst_db2'}
steps {
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[credentialsId: 'a84f7197-929a-437e-9aac-ca09fcd4c63a',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: '',
remote: 'svn://XXXXX/XXX/tags/CR/Rebuild_VCRDWD01']],
workspaceUpdater: [$class: 'CheckoutUpdater']])
sh 'Rebuild_VCRDWD01/recreate_db.sh'
}
}
}
}
Is there anyway we can get rid of this errors?
Environment:
Jenkins Version : 2.32.2
Running on Windows Server 2012 R2
Swarm Client 3.3 on AIX 7.1 and JDK 8
Also raised a Jenkins issue: https://issues.jenkins-ci.org/browse/JENKINS-42428
A user in the ticket mentioned previously reported that they were able to get rid of the error by downgrading the "Pipeline: Nodes and Processes" plugin in Jenkins to 2.8 - available from here. I was able to get rid of the problem as well by doing that. Unfortunately there are a number of other plugins I have installed that are dependent on version 2.10. I'm not keen on backleveling all of those, so guess I'm going to have to live with this as an annoyance until there's an official fix from the plugin maintainer. Hopefully that will be soon.

FindBugs warnings not displayed in Jenkins Dashboard

I am using a Multibranch Pipeline job to trigger my build. One of the steps of the build is to run Sonar. After the Sonar is run, findbugs-result.xml file is created the target/sonar directory.
I publish the results using the below commands in Groovy. The build shows that there is 1 warning for FindBugs. But I do not see in the Jenkins Dashboard (FindBugs Warning portlet).
If I create a normal Freestyle job and try to do the same thing using a Post-build action, the results are visible on the Jenkins Dashboard.
bat "${env.M2_HOME}/bin/mvn sonar:sonar --settings ../HudsonSettings/settings.xml -B -U -P reporting-plugins"
step([$class: 'FindBugsPublisher', canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', isRankActivated: true, pattern: '**/target/sonar/findbugs-result.xml', unHealthy: ''])
Can anyone help ?
Thanks and Regards
Saroj Gharat
By default, the Jenkins-Findbugs will look for files with the name findbugsXml.xml.
If your integration is dropping a report with a report filename, you need to add the filename findbugs-result.xml (Under Post-build action > Publish FindBugs analysis result > Findbugs results).

Cobertura code coverage report for jenkins pipeline jobs

I'm using the pipeline plugin for jenkins and I'd like to generate code coverage report for each run and display it along with the pipeline ui. Is there a plugin I can use to do that(e.g. Cobertura but it doesn't seem to be supported by pipeline)?
There is a way to add a pipeline step to publish your coverage report but it doesn't show under the BlueOcean interface. It will show fine in the normal UI.
pipeline {
agent any
stages {
...
}
post {
always {
junit '**/nosetests.xml'
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/coverage.xml', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])
}
}
}
Note that one of the parameters to the Cobertura plugin is the XML that it will use ('**/coverage.xml' in the example).
If you are using python, you will want to use something like:
nosetests --with-coverage --cover-xml --cover-package=pkg1,pkg2 --with-xunit test
Nowadays you can also use the cobertura command directly in a Jenkinsfile
stage ("Extract test results") {
cobertura coberturaReportFile: 'path-to/coverage.xml'
}
source: https://issues.jenkins-ci.org/browse/JENKINS-30700
The answer from hwjp is correct, however there are extra parameters that you can add to the command that are not easy to find.
Once you have installed the Cobertura plugin, you can find the cobertura step options in
Job Dashboard Page -> Pipeline Syntax -> Steps Reference
There's also a snippet generator which is really useful to get started at
Job Dashboard Page -> Pipeline Syntax
example command:
cobertura coberturaReportFile: 'coverage.xml', enableNewApi: true, lineCoverageTargets: '80, 60, 70'
enableNewApi is a good one to set to true, as the new API is much prettier :D
setting coverage targets will automatically fail the job if the code coverage is too low
Generate report using command line cobertura-report in specified directory and attach results as artifacts.
cobertura-report [--datafile file] --destination dir [--format
html|xml] [--encoding encoding] directory [--basedir dir]

Resources