Get jenkins all master/child job details using groovy - json

I need to get jenkins all master/child job details like start time, end time, review id which got integrated in current jenkin job for all the master and children jobs and put the same in a json array. I have written below script to get the details but not able to get start and end time of the job for master/child and how do we differentiate between master job detail and child job detail data.
import hudson.model.*
map1=[:]
map1["BUILD_NUMBER"]=(build.getEnvVars()['BUILD_NUMBER'])
map1["PARENT_BUILD_NUMBER"]=(build.getEnvVars()['BUILD_NUMBER'])
map1["JOB_NAME"]=(build.getEnvVars()['JOB_NAME'])
map1["PHASE_NAME"]=(build.getEnvVars()['JOB_NAME'])
map1["Status"]=(build.getEnvVars()['PHASE_RESULT'])
map1["Branch"]="master"
map1["JOB_URL"]=(build.getEnvVars()['JOB_URL'])
map1["START_TIME"]=(build.getEnvVars()['timestamp'])
map1["END_TIME"]=(build.getEnvVars()['buildEndTime'])
def json = new groovy.json.JsonBuilder()
json MasterJob: map1
println "json output: "
println groovy.json.JsonOutput.prettyPrint(json.toString())
Jenkin job image

You can get that information using Jenkins' REST API. It provides build information in various formats (including JSON). Example url:
http://JENKINS_HOST:8080/job/JOB_NAME/lastSuccessfulBuild/api/json?pretty=true
You have also a link to REST API documentation in bottom right corner of your Jenkins instance.

Related

Mention user on description Microsoft Azure DevOps API

I'm Using Azure devops API to get the description of a Pull Request and then take that description and paste it into another workitem using update api
This is an example of the description that i copy
Take a look at the **#Susan mention **at the very bottom, this is how it looks on HTML:
My question here is if there is an API to bring the whole description formatted, because this is what i get as description when i use the GET API
"description": "Summary:\nSome modifications to fix an issue in
the **** DPIDs startup code. \n\nBefore:\nThe PID stream startup
function is called continously when the TCM is not
responding.\n\nNow:\nThe PID stream startup is only executed one
time.\n\nTo Test:\nUse the next ECU Emulator
branch:\n*********\nEnable the vehicle and disable the TCM
module. Run the ECU Emulator. Run the Auto Agent. Open the mobile app.
Check in the serial output that The DPIDs are started only
once.\n\n#<6D4D***297> Pulled down on 8/12/2020, no more
looping PID stream startup without TCM. Looks good.",
it would also be nice to know how to attach by this way an image, when i get the description it shows like this: ! [ image (2).png ](https://dev.azu re.com/*/ /_apis/git/repositories/ac324630-b697-4990-ac7a-cb82443762d2/pullRequests/390/attachments/image%20(2).png)**
API can only get data, it's not able to get the page style. You may add the link to access the page directly.

How can I get microphone dB level in a script?

I would like to get microphone input level in spark ar script for an AR filter I'm developing.
It looks like this existed at this link at some point but the page is empty now: https://sparkar.facebook.com/ar-studio/learn/documentation/tutorials-and-samples/audio-analyzer-and-energy-meter/
I tried to create a bit crusher patch and connect its output to a value patch and pass that to script but spark ar shows an error: "Please check the patch graph and try again"
Also I have no idea what type that would be so I can't read it on the script.

Autodesk Forge register job conflict

When POSTing to https://developer.api.autodesk.com/viewingservice/v1/register I sometiems receive the following error:
{
Diagnostic: The request is rejected as it conflicts with a previous request that is in-progress.,
registerKeys: {},
Result: Conflict
}
How can I find out which job is already in progress so that I can track its progress and get its result?
First, this is the old API, you need to consider using the ModelDerivtive API instead (ie https://developer.autodesk.com/en/docs/model-derivative/v2)
Like Xiaodond said there is no API to collect all jobs currently processing on your account. You need to request each URN manifest to determine how many jobs runs on this model as know you can translate to SVF, but also export to other formats such as obj, stl, ... when it is possible. Manifest end point and documentation here - https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-manifest-GET/
Last, we are working on a webhook solution which will be a better solution as a Webhook will call you back when a job is starting and completes. Webhooks aren't yet available at the time of this post, but you should be notified via the developer newsletter when it will be on production.
Hope that helps,

Jenkins and JUnit

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.

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".