Turn off archiving of Allure report - jenkins

Allure commandline 2.6.0;
Jenkins ver. 2.89.3;
I am using the following script (no any other post-build settings in job settings):
stage('Generate reports') {
allure([includeProperties: false,
reportBuildPolicy: 'ALWAYS',
results : [[path: allureResultsPath]]])
archive 'catalina.log'
}
This gives me the report, but also the following archive, attached to each run:
Is it required for Trend, history or something?
I'd like to turn it off as it is not used by me and only spends the disk's space.
Is it possible to turn it off using the pipeline script?

Okay, I looked at the plugin's code and as far as I can see, there is no way to turn off archiving the report. Because it is called right after the report is generated, without any conditions (see saveAllureArtifact at 306 and it's call at 299):
https://github.com/jenkinsci/allure-plugin/blob/master/src/main/java/ru/yandex/qatools/allure/jenkins/AllureReportPublisher.java#L299

In allure plugin you can add attribute disabled
disabled (optional)
Type: boolean
So add disabled: true to your configuration:
allure(disabled: true, ...

Related

Jenkins – How to add label to Jira issue from Jenkins pipeline

I developed automated tests in Java. The XML test report is generated with junit 5 and xray-junit-extension. This XML is currently being integrated in Jira/Xray, but unfortunately the labels are not being added to the issue.
I believe that the labels could be integrated in two different ways, 1) through this XML test report, or, alternatively, 2) through the Jenkins pipeline itself.
My XML contains the following property :
Click here to see the screenshot
Similarly to what is written in the Xray documentation :
Click in order to see the screenshot of the documentation
https://docs.getxray.app/display/XRAY/Taking+advantage+of+JU...
The only difference is that in the Xray documentation there is a wrap around the tags property. In my XML I do not have that wrap.
Do you happen to have any idea on why the label is not being added in Jira/Xray?
The second approach would be using the XrayImportBuilder to add a label, using importInfo
step([$class: 'XrayImportBuilder',
endpointName: '/junit',
importFilePath: '/reports/.xml',
projectKey: 'P34AMA',
importToSameExecution: 'false',
//testExecKey: 'TSTLKS-753',
serverInstance: '3146a388-d399-4e55-ae28-8c65404d6f9d',
credentialId:'55287529-194d-4e91-9964-7d740d8d2f61',
importInfo: "{ "fields": {"labels": ["label"]}",
//importInfo = '{"fields": {"labels": ["EOD"]} }'
])
Problem using XrayImportBuilder in Jenkins
But when adding importInfo to my pipeline it ends with an issue :
Click here to see the Jenkins logs
Clcik here to see the Jenkins Import Step
Is anyone aware of any other way to add a label to jira automatically without using the hudson.plugins.jira.JiraIssueUpdater ?
Thank you very much for your help!

Publishing Static Code Metric reports in Jenkins using declarative pipeline(Jenkinsfile)

I am building a simple CI pipeline for my python code in Jenkins using Jenkinsfile, which basically does the following things:
Creating test environment and installing dependencies.
Running static code metrics:
various raw metrics : SLOC, comment lines, blank lines, Cyclomatic Complexity, the Maintainability Index etc.
tests coverage reports using coverage
errors and style check using pylint
Testing pulled source code (Unit testing)
So lets say i have this stage for example, for "Static code metrics":
...
stage('Static code metrics') {
steps {
echo "Raw metrics"
sh ''' radon raw --json my_python_repo/ > raw_report.json
radon cc --json my_python_repo/ > cc_report.json
radon mi --json my_python_repo/ > mi_report.json
//TODO: add conversion and HTML publisher step
'''
}
}
...
As you see above, the reports are saved in .json format. I need to figure out a way to publish these reports in a pretty visual way on Jenkins dashboard.
One of the steps is to convert the .json files to HTML and then use HTML publisher plugin to publish reports but i don't know what tool to use.
If there is way to solve this or any other way to publish these reports on jenkins dashboard, please provide the solution.
Lets say content of mi_report.json is:
{"my_python_repo/code.py": {"mi": 16.42950884051172, "rank": "B"}, "my_python_repo/test.py": {"mi": 33.532817596089814, "rank": "A"}}
There is no Jenkins-ready tool to publish custom JSON as HTML.
But you can use warnings plugin to publish your metrics in the Jenkins way.
Here small instruction on how to configure Jenkins to parse radon reports.

Jenkins declarative pipeline : How to configure the klocwork result display on the job page

I am creating a pipeline using the declarative pipeline flavour, with clockwork steps enclosed within a klockwork wrapper where I can define the klocwork setup :
klocworkWrapper(installConfig: 'My Klocwork', ltoken: "${HOME}/.klocwork/ltoken", serverConfig: 'Klocwork#XYZ', serverProject: 'S3cr3TPr0j3ct') {
klocworkBuildSpecGeneration([additionalOpts: '', buildCommand: 'make', ignoreErrors: true, output: 'kwinject.out', tool: 'kwinject'])
klocworkIntegrationStep1([additionalOpts: '', buildSpec: 'kwinject.out', disableKwdeploy: false, ignoreCompileErrors: true, importConfig: '', incrementalAnalysis: false, tablesDir: 'kwtables'])
klocworkIntegrationStep2([additionalOpts: '', buildName: "${JOB_BASE_NAME}_${BUILD_NUMBER}", tablesDir: 'kwtables'])
}
Ok, analysis is launched, and I can see the results on the Klocwork server web interface.
But I cannot find a way to retrieve resulting diagrams on the Jenkins web interface, even when using the pipeline script generator.
Unless I am totally wrong, I think that I should use klocworkQualityGateway, but the generated script snippet is not correct.
Once copied within the wrapper, it fails lacking for some enableXYGateway or gatewayXYConfig property.
For example this line :
klocworkQualityGateway([enableCiGateway: false, enableServerGateway: true, gatewayServerConfigs: [[conditionName: 'Issues', jobResult: 'failure', query: 'state:+Status,Fix', threshold: '1']]])
fails with an error message :
WorkflowScript: 92: Missing required parameter: "gatewayCiConfig" # line 92, column 1.
klocworkQualityGateway([enableCiGateway: false, enableServerGateway: true, gatewayServerConfigs: [[conditionName: 'Issues', jobResult: 'failure', query: 'state:+Status,Fix', threshold: '1']]])
I really cannot find a way to make it work, and I guess I can take a wrong turn... so any help would be appreciate.
Thanks for your help and best regards
J-L
Well, after a fruitful discussion with the plugin maintainer (M. Baron) it appears that there is currently no simple and direct solution to display Klocwork result on a pipeline job page.
He said :
This step doesn't have a native pipeline interface and a few people
have tried, but haven't had much success with workarounds to use this
in a pipeline.
The simplest thing to do seems to trigger a freestyle job that will only do that.
As far as I have understood, a new plugin version with full pipeline support will replace the current one.
So, I think this discussion can be closed.

file parameter in declarative pipeline

I am developing declarative pipeline and want to use file parameter to read its content, but its not working as expected
parameters{
file(fileLocation:'list.txt', description:'contains list of projects to be build')
}
I am getting following error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 12: Invalid parameter "fileLocation", did you mean "description"? # line 12, column 14.
file(fileLocation:'release-list.txt', description:'contains list of projects to be build')
Following is another option mentioned for basic step plugin
readFile: Read file from workspace
Reads a file from a relative path (with root in current directory, usually workspace) and returns its content as a plain string.
file
Relative ( /-separated) path to file within a workspace to read.
Type: String
encoding (optional)
Type: String
its working in script step like
def myfile = readFile('list.txt')
echo "${myfile}"
But how to use it directly in declarative script as we used other basic steps like dir??
The correct arguments for the file parameter are name and description. So it should be:
file(name:'list.txt', description:'contains list of projects to be build')
However there's an open jenkins issue dating back from 2015 about the file parameter not working for pipelines, so I don't think even this will solve your issue. https://issues.jenkins-ci.org/browse/JENKINS-27413
Following syntax is working
parameters{
file name:'list.txt', description:'contains list of projects to be build'
}
But fileLocation parameter is not acceptable still.
Below syntax is available in Jenkins2 Up & Running book but its not working
parameters{
file(fileLocation:'list.txt', description:'contains list of projects to be build')
}
Till outstanding issues gets fixed, I believe we may have to stick to freestyle mode & handle things either in downstream pipeline job or within same job leveraging needy plugin feature.
Here is my attempt which looks to work file irrespective (yes supports Binaries as well) types : https://i.stack.imgur.com/vH7mQ.png
${list.txt} will point to right file in your case..
Take a look at the plug-in https://plugins.jenkins.io/file-parameters/.
This plug-in adds support for file parameters in your Jenkinsfile: https://plugins.jenkins.io/file-parameters/#plugin-content-usage-in-declarative-pipeline
parameters {
base64File 'small'
stashedFile 'large'
}
https://github.com/jenkinsci/file-parameters-plugin

Jacoco 0% Code Coverage

My Code Coverage in Sonar is showing 0% which isn't true as I do have Unit Tests.
Gradle
sonarqube {
properties {
property "sonar.binaries", "build/intermediates/classes/release"
property "sonar.java.binaries", "build/intermediates/classes/release"
property "sonar.java.test.binaries", "build/intermediates/classes/test/release"
property "sonar.sources", "src"
property "sonar.junit.reportsPath", "build/reports/tests/release"
property "sonar.java.junit.reportsPath", "build/reports/tests/release"
property "sonar.android.lint.report", "build/outputs/lint-results.xml"
property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/testReleaseUnitTest.exec"
}
}
When I open up the index.html inside build/reports/tests/release then I can see successful unit tests.
I run sonarqube as a gradle task within my Jenkins environment. My SonarQube instance shows Code Smells and everything but for code coverage, it shows 0%.
Update
I do get an index.html created for the Code Coverage but that's all showing 0% too:
app/build/reports/jacoco/jacocoTestDebugUnitTestReport/html/index.html
Update
Still getting 0% but this is what I have so far:
android {
...
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testCoverageEnabled true
}
debug {
testCoverageEnabled true
}
}
jacoco {
version "0.7.8.201607051106"
}
}
Excerpt from SonarQube Documentation:
The Java Plugin reuses reports; it does not generate them. So before trying to configure your analysis to import these reports, make sure they are correctly generated and non-empty.
Since you don't seem to be using the Gradle Jacoco plugin, SonarQube is probably reporting that 0% because you have not generated a report. You will need to add Jacoco to your build and ensure that you have fed SonarQube the path of the generated report (sonar.jacoco.reportPath) so it can read it.
To add Jacoco to your project, you will need to add the following to build.gradle:
//...
apply plugin: "jacoco"
//...
jacoco {
toolVersion = "0.7.6.201602180812"
//Note: unless "reportsDir" is set here, default is “$buildDir/reports/jacoco”
}
You will also need to ensure the following: First of all, you need to ensure the jacocoTestReport task is being executed (either by adding it to tasks yourself; or by adding the task to your gradle invocation). Secondly, you need to make sure that SonarQube is looking in the correct location for the test report by setting sonar.jacoco.reportPath to point to your /reports/jacoco directory (it's defaulting to target/jacoco.exec, so it won't find a report on default settings).
I fixed the issue by using this plugin. The problem as I see it was that Jacoco was trying to look for Instrumentation Tests androidTests and not Unit Tests tests. The plugin which I used made sure that it ran the tests before hand, created a report based on the tests AND make Jacoco point to those tests.

Resources