How To Fail the 'war' build from within _Events.groovy? - grails

I want to fail the build within my eventListener closure in _Events.groovy under certain circumstances.
I've attempted two approaches:
Throw a RuntimeException()
call ant.fail('failing the build')
I get the following output in the console for both:
| Building WAR file.....
running event listener code...
[ERROR] Invalid environment argument of: 'tingaeuaeou', must be either 'testing', 'package', 'production' or 'native'
| Error Exception occurred trigger event [CreateWarStart]: Sencha SDK optimization failed. (Use --stacktrace to see the full trace)
| Done creating WAR target/product-selector-0.1.war
grails>
Here is my code I've written to attempt to fail the build:
...
ant.exec(outputproperty: "cmdOut", executable: 'sencha',
dir: "$stagingDir", failOnError: true) {
arg(value: 'app')
arg(value: 'build')
arg(value: "-e $senchaEnvironment")
}
def commandOutput = ant.project.properties.cmdOut
println "${commandOutput}"
if(commandOutput.contains('ERROR')){
ant.fail(message:"Sencha SDK optimization failed.",status:1)
}
...
The problem is that the war script keeps on running, generating a war file that will be broken, and I don't think my build process will report an exception happened; my continuous integration build will report a false success!
Any ideas?

Related

Allure report generated from Jenkins job returns 404

I'm trying to use the allure report plugin with Jenkins on CentOS7 for a Java maven project that is using TestNg and Allure test adaptor. The tests run fine and allure-results are generated as expected. My build step in the Jenkins file is
post {
always {
script {
allure([
commandline: 'allure',
includeProperties: false,
jdk: '',
properties: [],
reportBuildPolicy: 'ALWAYS',
results: [[path: target/allure-results]]
])
}
}
}
I can see the little allure icon in front of the build and when I click on it I get routed to http://xxx.xx.x.xx/index.html#404 with the following information:
URI: /index.html
STATUS: 404
MESSAGE: Not Found
SERVLET: Stapler
In the Jenkins build logs I see the following:
$ /bin/allure generate "/home/path/to/job/target/allure-results" -c -o "/home/path/to/job/allure-report"
WARN: No current version specified. Use `allure switch <version>` to select version of the report.
Allure report was successfully generated.
Creating artifact for the build.
Artifact was added to the build.
Finished: SUCCESS
When I manually try generating the allure report using allure serve, I can view the HTML report in the browser. But it's returning 404 in the Jenkins job.

Jenkins build gets failed, when unit test cases are failed

Jenkins build gets failed, when unit test cases are failed,
Here am using pipeline script in jenkins, Need to generate HTML report using mocha-awesome, I can get the HTML report only when all test cases are passed, Build fails if any functions failed in my testcases.Here you can see the screenshot
The call to the unit test run returns with exit status 1.
What you can do is use the returnStatus option for the sh or bat step which will then not fail the build itself but leaves that up to you:
def exitStatus = sh returnStatus: true, script: 'unittests'
or:
def exitStatus = bat returnStatus: true, script: 'unittests.exe'
Having this you can selectively fail the build, i.e. if exitStatus == 1 then ignore as it signals a test fail, if it is anything but 0 or 1 then fail the build using the error step.

Jenkins not creating JUnit test reports from Katalon tests in Workspace

Yesterday, I wrote and ran a Katalon test suite, and today, I'm trying to integrate Katalon with Jenkins. I successfully setup Jenkins, created a new job for the Katalon testing, as per these instructions, but when I went to build it, I get failing builds.
In particular, this is the error message I keep getting :
Recording test results
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
Finished: FAILURE
I went ahead and copied the Reports folder structure from the project directory that I specified to the Jenkins workspace. Upon later inspection, I found that, when Jenkins was running the Katalon tests, the JUnit_Report.xml file was actually getting created in the project's Reports folder, instead of at %JENKINS_HOME%\workspace\[project name]\Reports. I explicitly told it to generate test reports to : Reports/LoginSuite/*/JUnit_Report.xml.
NOTE: I'm on a Windows machine.
How can I fix this so that I can display test results from Jenkins?!
UPDATE : I have revised my Windows shell code to the following
C:
cd C:\Katalon
katalon -runMode=console -projectPath="C:\Users\mwarren\Katalon Studio\TestProject" -reportFolder="../../.jenkins/workspace/Katalon Studio Tests/Reports" -reportFileName="report" -retry=0 -testSuitePath="Test Suites/LoginSuite" -browserType="Chrome"
and it's still giving me the same error, even though now the tests are being created there.
Report folder is generated in the jenkins job folder.
Reports/**/JUnit_Report.xml
PEBKAC, apparently. I should have, from the getgo, listened to Jenkins and set my Test Report XMLs as */JUnit_Report.xml
Copy all reports to a temp folder, rename each xml with test case name and then copy it back to junit folder.
testCasesTxt = sh (
script: 'sudo find $WORKSPACE -name "*.ts*" -type f -printf "%f\n"',
returnStdout: true
).trim()
testCasesTxt = testCasesTxt.replace(".ts", "")
testCases = testCasesTxt.split("\n")
for (int i = 0; i < testCases.size(); i++) {
script {
try {
wrap([$class: 'Xvfb']) {
sh """
cd /opt/katalon
./katalon -noSplash -consoleLog -runMode=console -projectPath=$WORKSPACE/"katalon-project.prj" -reportFolder="Reports" -reportFileName="report" -retry=0 -testSuitePath="Test Suites/${testCases[i]}" -executionProfile="qa" -browserType="Chrome"
"""
}
} catch (any) {
currentBuild.result = 'FAILURE'
throw any //rethrow exception to prevent the build from proceeding
} finally {
sh """
cd /home/environment/tmp/
cd Reports
mkdir ${testCases[i]}
cd $WORKSPACE
cp -r Reports/ /home/environment/tmp/Reports/${testCases[i]}
cd /home/environment/tmp/Reports/${testCases[i]}/Reports
mv JUnit_Report.xml JUnit_Report_${testCases[i]}.xml
cd $WORKSPACE
cp -r "Data Files/" "/home/environment/tmp/"
"""
//
}
}
}
According to this thread, this can happen when trying to execute two Katalon instances at the same moment.
If that's the case, try changing Jenkins number of executors 1.
If your report is at \Reports\20200611_172240\TestSuite1\20200611_172240/JUnit_Report.xml location in your project folder, then configure the folder path as below - /Reports///*/JUnit_Report.xml
as the 3 folders after report folder name are always going to change after each execution.
Please use the Test report XMLs path as like this
**/target/surefire-reports/*.xml

Grunt html validator : Avoid Jenkins mark build as failure on connection timeout / reset

I am using: https://www.npmjs.com/package/grunt-html-validation
Here is my validation task in Grunt:
validation: {
partial: {
options: {
reset: grunt.option('reset') || true,
stoponerror: false,
failHard: true,
maxTry: 1,
doctype: 'HTML5',
relaxerror: []
},
files: {
src: [
'apps/www/partials/*.html',
'apps/www/partials/**/*.html'
]
}
},
After a lot of build the connection is refused by the W3C which is fine but I do not want to fail the build in Jenkins for this reason:
Error: 32mValidation started for..
[39mapps/www/partials/asset-library.html [31mFatal error: read
ECONNRESET[39m
Consider Text-finder plugin. Have your tests produce 0 exit code (so the build doesn't fail outright). Then configure a regex in Text-finder plugin, to search through your console log (or other workspace files).
Configure the regex in such a way that it searches for all test failure results (other than connection timeout). If found, mark the build FAILED (or UNSTABLE would be preferred to differentiate build failure vs test failure)

Casperjs export XML to Jenkins

I successfully setup a casperjs test exporting a "result.xml" file.
In Jenkins, I execute the following shell command:
casperjs /home/testing-radu/generated-test.js
This produces "results.xml" in my build's workspace.
In post-build actions I added "Publish XUnit test result report". I don't know how and where to setup the path to the .xml file.
When my build console I see the following:
[37;42;1mPASS 2 tests executed in 9.96s, 2 passed, 0 failed. [0m
[32;1mResult log stored in results.xml [0m
[xUnit] [INFO] - Starting to record.
ERROR: Publisher org.jenkinsci.plugins.xunit.XUnitPublisher aborted due to exception
/var/lib/jenkins/jobs/17live2/workspace/generatedJUnitFiles does not exist.
I added full rights to the workspace directory. I tried creating "generatedJUnitFiles" folder and here is what I'm getting:
[37;42;1mPASS 2 tests executed in 5.296s, 2 passed, 0 failed. [0m
[32;1mResult log stored in results.xml [0m
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Setting the build status to FAILURE
[xUnit] [INFO] - Stopping recording.
Build step 'Publish xUnit test result report' changed build result to FAILURE
Finished: FAILURE
Am I missing something?
Allright, here's the deal:
Under publish XUnit test results I chose JUnit (also setup the pattern to *.xml) and then
created a shell script to be executed by Jenkins:
# Auth tests
for f in auth/*.js ; do casperjs "$f"; done;
# Clean the old results and place the new ones
rm /var/lib/jenkins/jobs/17live2/workspace/*.xml
mv *.xml /var/lib/jenkins/jobs/17live2/workspace/
In Jenkins config I just do: ./run.sh
***You need read/write rights over your folders.

Resources