Timestamp mismatch in Jenkins Maven project - maven

I am using Jenkins version of 2.289.3. And I am working on a Maven-TestNG Selenium project in it. I have added Build Timestamp plugin and setup it in Manage Jenkins -> Configure System -> Build Timestamp with a pattern yyyy.MM.dd.HH.mm.ss of Asia/Calcutta. I am using Publish Html reports in Post Build action of that job's configuration. I have given path for HTML directory to archive is:
test-output\reports\report_${BUILD_TIMESTAMP}
But when running this job, the time stamp is not matching for publishing html report. End-portion of my comsole output is given below:
ChromeDriver was started successfully.
Aug 03, 2021 4:55:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 41.343 sec - in TestSuite
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[WARNING] Could not delete temp directory
C:\Users\CS1027C\.jenkins\workspace\SeleniumTestNG\target\surefire because Directory
C:\Users\CS1027C\.jenkins\workspace\SeleniumTestNG\target\surefire unable to be deleted.
[JENKINS] Recording test results
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:05 min
[INFO] Finished at: 2021-08-03T16:56:22+05:30
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving C:\Users\CS1027C\.jenkins\workspace\SeleniumTestNG\pom.xml to
MockTest/MockFrameTest/0.0.1-SNAPSHOT/MockFrameTest-0.0.1-SNAPSHOT.pom
channel stopped
[htmlpublisher] Archiving HTML reports...
[htmlpublisher] Archiving at PROJECT level
C:\Users\CS1027C\.jenkins\workspace\SeleniumTestNG\test-
output\reports\report_2021.08.03.16.54.51 to
C:\Users\CS1027C\.jenkins\jobs\SeleniumTestNG\htmlreports\HTML_20Reports
ERROR: Specified HTML directory 'C:\Users\CS1027C\.jenkins\workspace\SeleniumTestNG\test-
output\reports\report_2021.08.03.16.54.51' does not exist.
Build step 'Publish HTML reports' changed build result to FAILURE
Finished: FAILURE
Here the Chrome browser started at 4.55 but at post build action directory is created with timestamp containing 4.54. Why it is not taking the finishing time of the test? I can see a report folder generated at jenkins workspace is:
report_2021.08.03.16.55.36
Even I deleted the seconds from the time pattern, it is not matching with the generated report name. How can i fix this? Can anyone help me...Thanks in advance.

In my opinion the most probable explanation is as follows:
Build Timestamp plugin:
Export build timestamps to build env variables.
This is similar to setting environment variables via build parameters and the inline help of ☑ This project is parameterized reads:
Parameters allow you to prompt users for one or more inputs that will be passed into a build.
„passed into a build“ means that the environment variable is set before the first build step starts.
The output of a Freestyle test project with the following Execute Windows batch command build step confirms this (Timestamp plugin pattern is set to HH:mm:ss,S):
#echo off
echo Build step begin: %time%
:: let 10 seconds pass
ping -n 10 localhost > nul
echo Build step end: %time%
echo Build Timestamp: %BUILD_TIMESTAMP%
Console Output:
...
Build step begin: 21:19:33,88
Build step end: 21:19:42,90
Build Timestamp: 21:19:33,828
...

Related

Jenkins doesn't recognize Allure command

Hello Allure generators,
I'm trying to make Allure accessible to our testers in the company. I've installed Allure 2 through Scoop in the server and I'm able to run the cmd script: "allure serve" and see the results. So far so good. Now, my basic thought for solution is : run a "Post build actions" with a "Post build tasks" plugin with the allure serve command. The result is not good:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.801 s
[INFO] Finished at: 2018-06-25T11:08:28Z
[INFO] ------------------------------------------------------------------------
Performing Post build task...
Match found for : : True
Logical operation result is TRUE
Running script : cd C:\Projects\CarambolaClientTest2\target
allure serve
[Suite_runner] $ cmd /c call C:\Windows\TEMP\jenkins6058556997605873748.bat
C:\Program Files (x86)\Jenkins\workspace\Suite_runner>cd C:\Projects\CarambolaClientTest2\target
C:\Projects\CarambolaClientTest2\target>allure serve
'allure' is not recognized as an internal or external command,
operable program or batch file.
C:\Projects\CarambolaClientTest2\target>exit 9009
POST BUILD TASK : FAILURE
How can it be that "'allure' is not recognized.." ? It recognized it through the cmd (I've added it to the Environment variables of the machine and also to the environment variables in Jenkins configuration under Global properties).
I've also tried:
Create a Batch file with the script and run it in the post build
task (got the same result).
Add the Allure Plugin- but that's a
whole new problem- I'm getting an empty report.
Create new Job that only runs a "Windows batch command" with the allure serve, and it is running "Down stream" after the main Job runs (its the 2nd
project). Getting the same result.
Any ideas?
Thanks
You don't have allure executable in your PATH. Try to reload jenkins slave (or master) to see changes if you've added it to PATH before.
Also you can make Jenkins install allure automatically - find the a plugin for that

Jenkins "POM_VERSION" variable does not reset from build to build

Following Jenkins documentation jenkins docs
I can use the POM_VERSION environment variable to take the current version from the pom file.
But for some reason the POM_VERSION environment variable is not being refreshed from build to build. for example:
I changed the version number manually but the build number that exported was the last from the previous build.
From my python script:
print 'Current version is ' + os.environ['POM_VERSION']
which gives the following log Current version is 0.1.5 which is clearly wrong because i changed it. you can further see it in my maven versions goal output:
[INFO]
[INFO] --- versions-maven-plugin:2.1:set (default-cli) # ep-reporter ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /var/lib/jenkins/jobs/exchange-planner- reporter/workspace
[INFO] Processing com.exelate:ep-reporter
[INFO] Updating project com.company:ep-reporter
[INFO] from version 0.1.8 to 0.1.6
Props: {project.version=0.1.6, project.artifactId=ep-reporter, project.groupId=com.company}
note that it went from 0.1.5 because i have a script that advances it. but maven clearly states that its changing it from 0.1.8 to 0.1.6 which is not what POM_VERSION says
Thanks.
That environment variable is set at the time Jenkins first reads your POM file. You are clearly changing it during the build.
If you are changing it during the build, you know what you are changing to, and you should use the same mechanism to display it later.
I had the same problem and I resolved it by setting "Check-out Strategy" option to "Always checkout a fresh copy" in Source Code Management section.

How does Hudson/Jenkins determine job result status?

I have a Hudson server that runs maven 3 jobs to compile Java code. In one instance, a particular job's build log indicates that the compilation and unit tests all ran successfully, and the build completed in a successful state and another chained job was called, all indicated that Hudson believed the job to be successful. The log shows:
20:44:11 [INFO] BUILD SUCCESS
20:44:11 [INFO] ------------------------------------------------------------------------
20:44:11 [INFO] Total time: 1:35:43.774s
20:44:11 [INFO] Finished at: Mon Mar 24 20:44:11 CDT 2014
20:44:40 [INFO] Final Memory: 51M/495M
20:44:40 [INFO] ------------------------------------------------------------------------
20:44:42 channel stopped
20:44:42 [locks-and-latches] Releasing all the locks
20:44:42 [locks-and-latches] All the locks released
20:44:43 Archiving artifacts
20:45:33 Updating JIRA-1234
20:45:33 Description set: 1.23.567
20:45:33 Labelling Build in Perforce using ${BUILD_TAG}
20:45:33 [jobname] $ /usr/local/bin/p4 -s label -i
20:45:33 Label 'hudson-jobname-45' successfully generated.
20:45:33 [DEBUG] Skipping watched dependency update; build not configured with trigger: jobname #45
20:45:33 Finished: SUCCESS
However, the Hudson job page shows a "red ball" and that job run is listed as "Last failed build (#45)" on the job page. When I look at the hudson#hudson:~hudson/jobs/jobname/builds/45/build.xml file, there is a line that says
<result>FAILURE</result>
Assuming this was where the final result was captured, I changed this to
<result>SUCCESS</result>
and reloaded the page, but the red ball is still showing on the job page for that instance. I have not restarted the server to attempt to re-read the info from disk.
To be fair, there were some environmental issues around this build. Some hours later, I got a message that more than one Hudson server instance was running against the same disk image and confirmed this with
ps -ef | grep hudson.war
on the server console, showing two running processes. The job page says this run "Took 0 ms", even though the log says "Total time: 1:35:43.774s". This is Hudson ver. 2.2.1 running on "CentOS release 5.4 (Final)".
My questions:
What are the criteria for each of the job statuses? (Stable, Failed, Unstable, Aborted and Disabled statuses)?
When and where is that data captured in the running server, and can it be modified?
You have too many questions in one post.
As for "What are the criteria for each of the job statuses? (Stable, Failed, Unstable, Aborted and Disabled statuses)?"
Disabled is when a project/job is disabled from configuration (done by user with permissions). This is not a run status.
The rest are Job Run statuses:
Aborted is when a run has been cancelled/aborted. This happens when a user (with permissions) clicks the red cross button to cancel a running build. I believe SCM checkout failure also causes aborted status (but not too sure about that)
Unstable is a special status that can be applied to the job run. Usually this is done by job configuration (such as Maven) or through plugins such as Text-finder plugin. I am not aware of a way to induce unstable status through command line. Maybe through a groovy script, like plugins do. Most of the times, unstable is set by the job configuration itself, indicating failed test.
Stable and Failed are the direct result of Build Step's exit code. If the build step, such as Execute Shell, exits with exit code 0, the build step is considered success. Anything other than 0 is considered failed. If during execution of a build step, the process exits with anything other than 0, it is considered failed. If there are multiple build steps (Free-style project jobs), the last Build Step's exit code marks the status of the whole run. Once again, any Build Step in between that exits with anything other than 0 will mark the build failed.
Post-build actions, such as Text-finder plugin can also change the status of the job run.
You are not supposed to be tinkering with job history files to change the status of previous jobs. If you need to change the job result, use post-build actions such as Text-finder plugin, but even then, it only allows to downgrade the result.
Here's a one liner to printing the commit SHA1 in a jenkins job using groovy post-build script:
println "git rev-parse HEAD".execute().text
You can save this to a variable or export it as a build parameter.

Are there any jenkins variables for maven builds?

I am in need of accessing data that is produced through a maven build during a run on Jenkins which is then used in a curl command. This ultimately sends a message to a bot to post in a chat room. Plugins are not an option for this particular chat client unless I would be the one to make them. Any other plugins that would be able to execute curl or hit url are fine given I can get to the data.
Currently when I run the command
mvn surefire-report:report
I am able to see output like this from the job:
...
Results :
Failed tests:
passwordLengthRequirement(test.java.com.company.appium.suites.RegistrationTest): expected:<P[assword must be 6 characters or longer].> but was:<P[lease accept the Terms of Service].>
...
Tests in error:
SendText(test.java.com.company.appium.suites.ChatTest): Timed out after 10 seconds waiting for presence of element located by: By.xpath: //window[2]/UIAKeyboard[1]/UIAKey[5]
...
Tests run: 40, Failures: 3, Errors: 2, Skipped: 4
[ERROR] There are test failures.
Please refer to .../target/surefire-reports for the individual test results.
[INFO]
[INFO] <<< maven-surefire-report-plugin:2.16:report (default-cli) # ios_junit <<<
[INFO]
[INFO] --- maven-surefire-report-plugin:2.16:report (default-cli) # ios_junit ---
[WARNING] Unable to locate Test Source XRef to link to - DISABLED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17:26.412s
[INFO] Finished at: Mon Jan 13 11:19:25 EST 2014
[INFO] Final Memory: 16M/81M
[INFO] ------------------------------------------------------------------------
Recording test results
If there are variables that can be used to get the data that would be a huge help but I don't know what they are if they even exist. My latest attempt has been to use the Post Build Task plugin to access the build.xml or log files with completed output. When trying to grep the build.xml that is created and extract the data I need grep is not working for some reason
XML:
`<failCount>72</failCount>`
`<skipCount>4</skipCount>`
`<totalCount>76</totalCount>`
Command:
$FAIL_COUNT=grep "failCount" ../../builds/$BUILD_NUMBER/build.xml | cut -d">" -f2,2 | cut -d"<" -f1,1
Output:
+ =grep failCount ../../builds/25/build.xml
/var/folders/2b/jv3l9cys1sqbbk6l2hxx_n1000007c/T/hudson6366869578068337646.sh: line 3: =grep: command not found
This page has been helpful with getting other variables but does not list what could be available during a maven run
https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-JenkinsSetEnvironmentVariables
The message I am ultimately trying to send would be something like
Finished with status '$BUILD_STATUS'. Total tests run '$TOTAL_COUNT'. Total failed tests '$FAIL_COUNT'.
Thanks in advance for any suggestions.

Feeding emma coverage to sonar

I'm trying to feed sonar with emma results for a multimodule project
mvn sonar:sonar -Dsonar.dynamicAnalysis='true' -Dsonar.core.codeCoveragePlugin=emma -Dsonar.emma.reportPath=target
For each module I get:
instrumentation path processed in 1798 ms
[146 class(es) instrumented, 19 resource(s) copied]
metadata merged into [<module>/target/coverage.em] {in 152 ms}
and later:
[INFO] [12:24:32.514] Sensor EmmaSensor...
[INFO] [12:24:32.514] Parse reports: <module>/target
[WARN] [12:24:32.514] No coverage (*.ec) file found in <module>/target
[INFO] [12:24:35.123] Sensor EmmaSensor done: 2609 ms
So I get 0% coverage in sonar
Why is it trying to find .ec files instead of .em files?
Sonar version is: 3.5.1
Thanks
It would be nice if you mentioned the Sonar version you use.
However I think that the parameter sonar.dynamicAnalysis should have the value of 'reuseReports' and not 'true'
Also make sure that the em files are existing under the target folder
For more information see http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests+for+Java+Project
and
http://docs.codehaus.org/display/SONAR/Emma+Plugin

Resources