Jenkins and JUnit - configuration

I've read over the Jenkins site and its JUnit plugin, and for some reason something that is very basic is just not apparent to me.
Jenkins has an Email-ext plugin for sending custom/advanced notification emails whenever a build is ran. In these emails you can place "content tokens" that are runtime variables that get replaced with dynamic values when the email is being generated.
One of these tokens is TEST_COUNTS which allows you to display the number of JUnit tests that ran, or which failed, etc.
How does one go about getting Jenkins to display this information correctly? Is there a plugin I need, and if so, which one? I have my build running JUnit and generating an XML report. I assume Jenkins somehow parses JUnit results out of that XML and uses it to give values to that token.
But on the other hand, I've read "literature" (mailing list posts) that seems to suggest that in order to use that token you need to use Jenkins to run the unit tests, not a junit Ant task from inside your build script.
Can someone clarify this for me and perhaps even set out the "order of operations" for what steps I need to take in order to be able to make use of this token?
It would be supremely useful to get test counts in our build notifications.

Your first explanation is right. You tell Jenkins where to search for JUnit output files, and it parses them to find out the test results:
The test results appear on each project and build page, so as long as you're seeing the correct results there, you should get the correct token replacements in your e-mails

Add something like this to the content in the "Editable Email Notification" configuration:
Total = $TEST_COUNTS
Failed = ${TEST_COUNTS,var="fail"}
I also recommend the Jenkins users mailing list for Jenkins questions, usually helpful.

Related

What is the point of specifying parameters in GitHub Action Error/Warning/Notice Messages

According to the documentation for setting error (and warning) messages you can specify a number of parameters (file, line, col, etc). What is the intended purpose of this? I've spent a fair amount of hours attempting to make use of them but I can't see GitHub actually using them.
I can confirm that title and message does work. It would be very nice if this could link directly to the code into the pull requests or action results.

Is there a way to find the workitems for a release in Azure DevOps Api 5.1?

I can find a release in Azure DevOps Api 5.1 by a request to https://vsrm.dev.azure.com/mycompany/myproject/_apis/release/releases/myreleaseid?api-version=5.1
How can I get the workitems of that release as shown on the devops portal under Deployment - Stages - Workitems?
My naive approach just using https://vsrm.dev.azure.com/mycompany/myproject/_apis/release/releases/myreleaseid/workitems?api-version=5.1
resulted in a 404.
There is a stakeholder in the workitem and I want to send him a notification adter the release.
How can I get the workitems of that release as shown on the devops
portal under Deployment - Stages - Workitems?
Hard to say, but I don't find any document about this topic... So I determine to use F12 to find that. And here's the one I finally find:
Get:https://vsrm.dev.azure.com/mycompany/myproject/_apis/Release/releases/myreleaseId/workitems?baseReleaseId={my baseReleaseId}&%24top=250&artifactAlias={my artifactAlias}
It will returns the IDs of the workItems for the release. Its response format:
After you get the IDs, it's easy to get details if you need using Get Work Items Batch or what.
In addition:
1.myreleaseId is the ReleaseID. (On my side, the ID is 7 if it's Release-7)
2.my artifactAlias is this:
3.For my baseReleaseId, I'm not 100% sure about its meaning. I think it could be something like ReleaseToCompareAgainst. Hint from Daniel. (On my side, if my releaseId=7, then I use basereleaseID=6(7-1), it works to get the correct WIT ids). (Actually I suggest you can use F12 in that web page to check your corresponding URL.)
And according to Mathias F: The baseReleaseId realy is the last previous release that has a deployment (-1 in some cases)
4.About how to use F12 to find rest api which may not be documented:
Hope all above helps :)

How to List all test names in teamcity using REST API

I am trying to get List of tests as defined here.https://confluence.jetbrains.com/display/TCD8/REST+API#RESTAPI-Tests
But I can't get the list of test names from myteamcity/app/rest/testOccurrences?locator=buildType:(id:1140)]
Is there another way to get those List of passed/failed tests?
I know that long time has past since this question, but I accidentally stumbled upon it so here is the answer if someone else has a similar problem.
If I understood the Teamcity documentation correctly you can't use buildType with Tests. Supported locator is actually id of the exact build:
Rest API Tests
But what you can do is get the list of builds for a buildType:
http://myTeamCity:100/guestAuth/app/rest/buildTypes/id:AXPL_TestDaily/builds/
And then use one of these build ids to get the tests:
http://myTeamCity:100/guestAuth/app/rest/testOccurrences?locator=build:(id:109)
Considering that you wrote integer as an id in your example, maybe you just already have the correct id, but you have resource path wrong as it is not id for buildType, but for build, because buildTypes have strings for ids.

How do I get the Junit test results using Email-ext in Jenkins

What do I need to add to the default html_gmail.jelly script to have it show the classes that were tested including how many tests were ran within each class?
When a Jenkins job is complete you can drill down to the Junit Test Results in an address that looks like:
http://somecompany.jenkins.com/view/App_Automation/job/Application_Under_Test/129/testReport/com.AUT.testing.mobile/
The test results are generated by the build.xml so is it just a matter of pointing to that xml file?
The email-ext page shows a clean example but not the tokens that are used to achieve that: http://wiki.hudson-ci.org/download/attachments/3604514/html.jpg
Currently using the ${FAILED_TESTS} token generates a nice Tested; Failed; Skipped number, but nothing that points to which tests passed/failed/skipped. I would like to show the total number of tests including which tests were actually ran.
Thanks ahead of time
OK I figured out how to display the pass and failed methods by adding var=pass or var=fail to the token of those assignments.
First go to the Jelly script in the this path:
~/.hudson/plugins/email-ext/WEB-INF/classes/hudson/plugins/emailext/templates/automation.jelly
$DEFAULT_SUBJECT (${build.testResultAction?.failCount} ${build.testResultAction?.failureDiffString})
SETTING UP THE CONFIG IN JENKINS
DEFAULT SUBJECT:
$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!
DEFAULT CONTENT:
$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
Check console output at $BUILD_URL to view the results.
Changes:
${CHANGES}
Changes Since Last Success
${CHANGES_SINCE_LAST_SUCCESS}
Failed Tests:
${FAILED_TESTS}
Build Log:
${BUILD_LOG}
Total Amount of Tests:
${TEST_COUNTS, var}
Total = $TEST_COUNTS
Failed = ${TEST_COUNTS,var="fail"}
Total = $TEST_COUNTS
Passed = ${TEST_COUNTS,var="pass"}
Job Description:
${JOB_DESCRIPTION}
Place this in the email job
${JELLY_SCRIPT,template="html-with-health-and-console"}
Note the templates available are noted in the path ~/.hudson/plugins/email-ext/WEB-INF/classes/hudson/plugins/emailext/templates/automation.jelly or create your own.

Determine if given job is currently running using Hudson/Jenkins API

Is there an API to determine whether a given job is currently running or not?
Ideally, I'd also like to be able to determine its estimated % complete and get the details of the SVN revision number and commit comment too!
EDIT:
I found the answer. http://host/job/project/lastBuild/api/ has almost all of what I need in it somewhere! If you kick off a manual build, it won't tell you the SCM changesets, but that makes sense. It does still tell you the latest SCM revision though, so that's good. All in all, good enough for my purposes right now.
As gareth_bowles and Sagar said, using the Jenkins API is the way to know.
If you put the depth to 1, you will see what you're looking for:
http://host/job/project/lastBuild/api/xml?depth=1
You will see there's a <building> tag to tell if that build is running
...
<build>
<action>
<cause>
<shortDescription>Started by user Zageyiff</shortDescription>
<userId>Zageyiff</userId>
<userName>Zageyiff</userName>
</cause>
</action>
<building>true</building>
<duration>0</duration>
<estimatedDuration>-1</estimatedDuration>
<fullDisplayName>Project #12</fullDisplayName>
<id>2012-08-24_08-58-45</id>
<keepLog>false</keepLog>
<number>12</number>
<timestamp>123456789</timestamp>
<url>
http://host/job/project/12
</url>
<builtOn>master</builtOn>
<changeSet/>
<mavenVersionUsed>3.0.3</mavenVersionUsed>
</build>
...
I'm using the Groovy plug-in, and run the following snippet as system:
import hudson.model.*
def version = build.buildVariableResolver.resolve("VERSION")
println "VERSION=$version"
def nextJobName = 'MY_NEXT_JOB'
def nextJob = Hudson.instance.getItem(nextJobName)
def running = nextJob.lastBuild.building
if (running) {
println "${nextJobName} is already running. Not launching"
} else {
println "${nextJobName} is not running. Launching..."
def params = [
new StringParameterValue('VERSION', version)
]
nextJob.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
}
It works like a charm.
If you go to your job's page, and add "api" to the end of the URL, you'll get information on using the API.
http://yourjenkins/job/job_name/api
More information on using the Jenkins API:
https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
If you're comfortable with digging through the Jenkins Java API, you could write a system Groovy script to get this data. The Job class is the place to start.
As stated on the /api page of your build (chapter "Accessing Progressive Console Output"), you can poll the console output with a GET request by calling <url-to-job>/lastBuild/logText/progressiveText. To quote the API doc:
If the response also contains the X-More-Data: true header, the server is indicating that the build is in progress
And there you go. You can test this behaviour by simply calling the respective URL in your browser and then inspecting the response headers with your browser's developer tools (usually accessed by pressing F12). In Firefox, the respective tab is called "network analysis" (assuming my translation is correct, my browser is not set to English). In Chrome, navigate to the "Network" tab.
This answer is based on Jenkins version 2.176.3.
It is also possible to look at the color attribute. I know it is not the wanted way. But maybe someone can make use of it.
get the overview xml via "/job/api/xml" and then check the color attribute for "anim".