Generate .trx file without timestamp - jenkins

Before the following command generates my-test.trx but by updating our server it generates my-test_2019-04-14_09-59-39-114.trx. And this is not mentioned in its document (https://aka.ms/vstest-report)
dotnet test --logger "trx;LogFileName=my-test.trx"
Now such this step in Jenkins cannot find the file with timestamp.
step([$class: 'MSTestPublisher', testResultsFile:"$TEST_PATH/TestResults/my-test.trx", failOnError: true, keepLongStdio: true])
Server's update list:
dotnet-runtime-deps-2.1:amd64 2.1.10-1
dotnet-host:amd64 2.2.4-1
dotnet-hostfxr-2.1:amd64 2.1.10-1
dotnet-runtime-2.1:amd64 2.1.10-1
aspnetcore-runtime-2.1:amd64 2.1.10-1
dotnet-runtime-deps-2.2:amd64 2.2.4-1
dotnet-hostfxr-2.2:amd64 2.2.4-1
dotnet-runtime-2.2:amd64 2.2.4-1
aspnetcore-runtime-2.2:amd64 2.2.4-1
dotnet-sdk-2.1:amd64 2.1.603-1
dotnet-sdk-2.2:amd64 2.2.203-1
Any idea how to stop adding this timestamp or fixing Jenkins code?

Fixed the Jenkins pipeline this in way:
script {
TRX_FILE = sh (script: "ls $TEST_PATH/TestResults/my-test*.trx", returnStdout: true).trim()
}
echo "TRX_FILE : ${TRX_FILE}"
step([$class: 'MSTestPublisher', testResultsFile:"$TRX_FILE", failOnError: true, keepLongStdio: true])

Related

Jenkins Pipeline: No Such DSL Method ‘perfReport’ found

I am getting the error No such Dsl method ‘perfReport’ found
post {
always
// sh '1s -ltr target/jmeter/reports*
sh sh
mkdir -p target/jmeter_results/*
sh
"cp -a target/jmeter/reports/*/* target/imeter results/"
sh
'op -a target/jmeter/results/*.cav target/jmeter_results/results.txt*
"ep -a target/jmeter/logs/*.log target/jmeter_results/Jmeter.jmx.log* sh
'ls -ltr target/imeter results/' archiveArtifacts artifacts: 'target/imeter results/*, allowEmptyArchive: true, fingerprint: true, caseSensitive: true, onlyIf
publishHTML (target: [allowMissing: false, alwayslinkToLastBuild: true, keepAll: false, reportDir: "target/imeter results/. reportFiles:
index.html'
reportName:
"Performance Test Result*
//reportTitles:
])
perfReport errorFailedThreshold: 5, errorUnstableResponseTimeThreshold: 'results.txt:1000*, errorUnstableThreshold: 2, excludeRespe
changed {
notifybuildstatus (currentBuild.currentResult)
def notifybuildstatus (buildstatus)
def status
switch (buildStatus) {
case SUCCESS' :
status = ' GREEN*
break
case 'UNSTABLE*:
status = 'AMBER*
break
case FAILURE::
status break
"RED*
This error can mean:
The performance plugin isn't installed on your jenkins. This post explains how you can see which plugins are installed.
You have a typo, and a property name is wrong, or the type of the value different than the expexted, e.g. the plugin expects a bool but you're passing a string.
From your code, the value of errorUnstableResponseTimeThreshold has an asterisk (*) instead of the closing quote ('). That may be the cause. The command is truncated so it's hard to say if the other keys have valid values.
You can try using the pipeline snippet generator to ensure your syntax is correct, but I'm not sure if it's supported for this plugin.

Publishing newman-reporter-htmlextra reports with Jenkins html publisher fails

I am running newman with newman-reporter-htmlextra in a Jenkins pipeline, generating a html report which I want to publish via the jenkins html publisher.
This is the stage in the pipeline I´m using
stage('Newman tests') {
steps() {
script {
dir("${JENKINS_HOME}/workspace/myproject") {
sh 'newman run "./Collections/my_collection.postman_collection.json" --reporters cli,junit,htmlextra --reporter-junit-export "newman_result.xml" --reporter-htmlextra-export "newman_result.html"'
junit "*.xml"
}
}
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: '.',
reportFiles: 'newman_result.html',
reportName: 'Newman HTML Reporter'
]
}
This is running, and creating an entry Newman HTML Reporter in my Jenkins project.
However, when I open such a report, it is empty, pls check .
Any ideas?
Many thanks in advance,
Christian
I guess you are accessing the wrong folder when you want to publish your html result.
You are creating your file not in the regular jenkins workspace:
dir("${JENKINS_HOME}/workspace/myproject") {
sh 'newman run "./Collections/my_collection.postman_collection.json" --reporters cli,junit,htmlextra --reporter-junit-export "newman_result.xml" --reporter-htmlextra-export "newman_result.html"'
junit "*.xml"
}
After you are leaving the script{} you are accessing the original workspace of Jenkins so reportDir: '.' is not the same folder where your file is which means no file = no html can be displayed.
You have 3 choices here:
You create the file in the regular workspace of Jenkins
The HTML Publisher Plugin aims to the correct folder
Put the HTML Publisher plugin into the scope of your dir{} as you did with your junit plugin
To find out easily which folder you are accessing in which scope you can run an echo pwd. Do this once in the scope of your dir{} and once in the scope of your plugin then it should be clear that the reportDir of your plugin is wrong.

How to export a variable from sh step to outside sh step in jenkins

I am trying to email the output of a file after a build. The build updates the file file1.json. Her is my problem. After build I am trying to create a variable which cat the file1.json ( this is working) , then I am trying to email that variable in emailext.
Stage {
stage('Build'){\
sh """
npm install // builds and update the value in json file
UUID="`cat file1.json`" //outputs the string inside file which is what I want
echo \$UUID //shows the value here
"""
emailext body: "$UUID", //need the value here
subject: "$currentBuild.currentResult-$JOB_NAME",
to: 'someone#test.com'
}
`
The error message is groovy.lang.MissingPropertyException: No such property: UUID for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
at
You can use option returnStdout: true of sh() step to get the output of shell.
stage('Build'){
script {
sh 'npm install' // builds and update the value in json file
UUID = sh (script: 'cat file1.json', returnStdout: true).trim()
emailext body: "$UUID", subject: "$currentBuild.currentResult-$JOB_NAME", to: 'someone#test.com'
}
}

Jenkins Pipeline publish html report

Maven clean install generate new html file in following location
/var/lib/jenkins/workspace/Docs_LoadTest/target/jmeter/reports/DocsJmeterTests_20170601_151330/index.html
Here "DocsJmeterTests_20170601_151330" will change for every run. So i am trying to publish html report using publish html report plugin. Following is my Pipeline script
node {
build job: 'Docs_LoadTest'
stage('Results') {
publishHTML([allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir:
'/var/lib/jenkins/workspace/Docs_LoadTest/target/jmeter/reports/*/',
reportFiles: 'index.html',
reportName: 'Docs Loadtest Dashboard'
])
}
}
Getting following error while running the job
[htmlpublisher] Archiving HTML reports...
[htmlpublisher] Archiving at BUILD level
/var/lib/jenkins/workspace/Docs_LoadTest/target/jmeter/reports/* to
/var/lib/jenkins/jobs/Docs_Pipeline/builds/10/htmlreports/Docs_Loadtest_Dashboard
ERROR: Specified HTML directory '/var/lib/jenkins/workspace/Docs_LoadTest/target/jmeter/reports/*' does not exist.
Even we tried following options didnt worked
/var/lib/jenkins/workspace/Docs_LoadTest/target/jmeter/reports/**/
/var/lib/jenkins/workspace/Docs_LoadTest/target/jmeter/reports/DocsJmeterTests_*
/var/lib/jenkins/workspace/Docs_LoadTest/target/jmeter/reports/DocsJmeterTests_*
_*
The HTML Publisher plugin does not seem to understand wildcards. What you could do in your Pipeline is using Linux's copy command, since that can work with wildcards.
This copies over the contents of all directories in the [Docs_LoadTest]/jmeter/reports folder to a jmeter_results folder in the local workspace:
sh 'cp -r /var/lib/jenkins/workspace/Docs_LoadTest/target/jmeter/reports/*/. target/jmeter_results/'
Note that you must clean both your target folder in the Docs_LoadTest folder and your Pipeline in between runs, else multiple reports will be copied over with this solution.
A better solution:
Would be to apply this trick in the Docs_LoadTest and use the Publish Artifact and Copy Artifact features. This works around having to hardcode the path to the other job and will work even if the Pipeline executes on another slave than the Docs_LoadTest. This does require the Copy Artifacts plugin.
Assuming Docs_LoadTest is a Freestyle job:
Add an Execute Shell Build step that copies the results to a fixed folder, e.g. jmeter_results:
mkdir -p target/jmeter_results/
cp -r target/jmeter/reports/*/. target/jmeter_results/
Then add an Archive Artifacts Post Build Archive Step with the following files to archive:
target/jmeter_results/*
In your Pipeline:
Use the Copy Artifact step to copy the files to target/jmeter_results folder in the local workspace:
step ([$class: 'CopyArtifact',
projectName: 'Docs_LoadTest',
filter: 'target/jmeter_results/*']);
Change the call to the HTML publisher to use this folder:
publishHTML([allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'target/jmeter_results',
reportFiles: 'index.html',
reportName: 'Docs Loadtest Dashboard'
])
I was having similar problem, only that I wanted to publish multiple reports.
What I ended up doing was I added simple groovy script to iterate through files in reports directory. You can use same/similar approach to get file name.
stage('publish reports') {
steps {
unstash 'source'
script {
sh 'ls target/jmeter/reports > listFiles.txt'
def files = readFile("listFiles.txt").split("\\r?\\n");
sh 'rm -f listFiles.txt'
for (i = 0; i < files.size(); i++) {
publishHTML target: [
allowMissing:false,
alwaysLinkToLastBuild: false,
keepAll:true,
reportDir: 'target/jmeter/reports/' + files[i],
reportFiles: 'index.html',
reportName: files[i]
]
}
}
}
}
Note: this example is used in declarative pipeline. Docs about readFile function.
I have tried simply the followings.
stage('Test-Junit') {
steps {
sh 'gradle test'
}
post {
always {
script {
def moduleNames = ["app", "core", ...]
for(i=0; i<moduleNames.size(); i++ ) {
publishHTML target: [
allowMissing:false,
alwaysLinkToLastBuild: false,
keepAll:true,
reportDir: moduleNames[i] + '/build/reports/tests/test',
reportFiles: 'index.html',
reportName: 'Test Report:' + moduleNames[i]
]
}
}
}
}
}
It will make all modules report and thus you can find them on left nav-bar of project dash-board.
It is not exactly the same scenario, but decided to publish my code because was really hard to understand, clarify and get documentation and accurate examples on how to publish different reports in just one final consolidated report, using the publishHTML plug-in for Jenkins.
A bit of background, we are executing different packages of testing, but some test cases can't run together because they could kill each other, so we need to execute, from the same code, in two different time frames due that we run test cases in parallel.
The solution was to execute by tags, so once the different execution using a Jenkins DSL - pipeline happens the builds produce just one report with different tabs on it.
So this is the final code that works for me:
pipeline {
agent any
stages {
stage('Git') {
steps {
git .....
}
}
stage('Exec-1') {
steps {
bat 'mvn -B clean verify -Dcucumber.filter.tags=#exec1 -Dserenity.outputDirectory=reports/site/serenity/exec1'
}
stage('Exec-2') {
steps {
bat 'mvn -B clean verify -Dcucumber.filter.tags=#exec2 -Dserenity.outputDirectory=reports/site/serenity/exec2'
}
}
stage('Exec-3') {
steps {
bat 'mvn -B clean verify -Dcucumber.filter.tags=#exec3 -Dserenity.outputDirectory=reports/site/serenity/exec3'
}
}
}
post {
always {
publishHTML target: [
reportName: 'Test',
reportDir: 'reports/site/serenity',
reportFiles: 'exec1/index.html, exec2/index.html, exec3/index.html',
reportTitles: 'Exec-1, Exec-2, Exec-3',
keepAll: true,
alwaysLinkToLastBuild: true,
allowMissing: false
]
}
}
}

Jenkins Pipeline always fails

My Jenkins pipeline stages are all successful yet the build always says it failed. To be clear, the build was a success and I would like it to register with Jenkins as successful but for some reason Jenkins thinks it has failed. All the stages say success in the dashboard yet the build is marked with a red ball and the console output ends with Finished: FAILURE.
Here is my pipeline file
node {
try{
stage 'Clone repo'
sh 'gcloud source repos clone <repo-name> --project=<project-name>'
dir('<repo-name>') {
try{
stage 'Run tests'
sh './gradlew test'
stage 'Run integration tests'
sh './gradlew integrationTest'
publishHTML(target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: false,
reportDir: '<repo-name>/build/reports/integrationTest',
reportFiles: 'index.html',
reportName: 'Integration Test Reports'])
} finally {
stage 'Stop and remove docker containers'
sh 'docker-compose down'
sh 'docker-compose rm -f'
}
}
} finally {
deleteDir()
}
}
I realised I had included the full path to the html reports when I was actually inside a dir block. There was no indication in the logs of this.
is your problem solved ?
Anyway the deleteDir function can be a problem sometimes. Because deleteDir recursively deletes the current directory and its contents, you can raise an error if you try to delete the complete job workspace.
Take care to use it in a dir function as below:
dir('directoryToDelete') {
deleteDir()
}

Resources