Getting Jenkins Build Results through HTTP Get request - jenkins

I'm trying to get test results from a Jenkins job and was wondering if it was possible to get the json results by making a GET request (e.g. to a certain job: JENKINS_URL/job/JOB_NAME/build/api/json) while not logged into the Jenkins server.
I am having trouble understanding how you can send all the how do you pass the authentication information in the API call (e.g. API token / password, username).
I know the Jenkins CLI is an option, but I would prefer not to use it if possible.
To be clear, when logged in on my computer, calls to JENKINS_URL/job/JOB_NAME/build/api/json yield the build results, but when I log out, the link takes me to the log in page.

You have to configure your credentials and give read access for anonymous or pass your user/password in your request:
curl --user username:password jenkins_url/job/job_name/build_number/api/json
The same but using api_token:
curl --user username:api_token jenkins_url/job/job_name/build_number/api/json
If you pass also?pretty=true parameter, you should see something like this:
{
"actions" : [
{
"parameters" : [
...
}
],
...
"building" : false,
"description" : null,
"displayName" : "#36",
"duration" : 1936,
"estimatedDuration" : 2020,
"number" : 36,
"queueId" : 224,
}

Related

create an identity that can issue other identities in hyperledger composer rest server

I checked that link and that there is an option --issuer or -x but what if I want to create an issuer identity from composer rest server ?
what are possible values that can be passed to that "options" field in the body of issue system identity request in the rest server ?
Under /System;
POST /system/identities/issue:
{ "participant": "resource:org.acme.mynetwork.BizAdmin#org1admin",
"userID": "jdoe", "options": {"issuer" : true} }
in the JSON data for the request.

Impossible to get messages details in a list request with Gmail API

I am using a ruby on rails app which connects to the Gmail API. When I make a listrequest to get all the messages of one mailbox, I only get back an idand a threadId property for each message.
I tried to follow Gmail API Doc using the fields parameters to get other properties (title, date...). It doesn't work, whether I use the google-api-client gem in my app, or by doing a direct GET request.
Adding any other parameters to the request ends with a failure. Here is the url that works :
https://www.googleapis.com/gmail/v1/users/me/messages?fields=messages(id,threadId)
Am I forced to make one call per message or using batch requests to get relevant datas ? It seems a little heavy...
You first need to list messages like you've done, and then get each message in a separate request.
Request 1
GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1&access_token={ACCESS_TOKEN}
Response 1
{
"messages": [
{
"id": "15fd9f0fe242f975",
"threadId": "15fd9f0fe242f975"
}
],
"nextPageToken": "11889180580605610074",
"resultSizeEstimate": 2
}
Request 2
GET https://www.googleapis.com/gmail/v1/users/me/messages/15fd9f0fe242f975?access_token={ACCESS_TOKEN}
Response 2
{
"id": "15fd9f0fe242f975",
"threadId": "15fd9f0fe242f975",
"labelIds": [
"IMPORTANT",
"CATEGORY_UPDATES",
"INBOX"
],
"snippet": "Tasks tracked last week...",
"historyId": "966691",
...
}
It's also possible to get the total amount of request down from 1 + n of messages to 2 by using batch requests.

BitBucket 1.0 REST API Retrieve all Pull-Requests for repository

When I curl the rest api, I get back an empty response but I know that there are pull-requests open.
What is the setting in bitbucket stash that allows anyone to view/read pull-requests without being authenticated?
curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests
response:
{
"size": 0,
"limit": 25,
"isLastPage": true,
"values": [],
"start": 0
}
Try
curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests?state=ALL
You can find more options for this specific API call at https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm140236731714560
This worked for me:
curl -D- -u user:password -X GET -H "Content-Type: application/json" -X GET https://bitbucket.com/rest/api/1.0/projects/ONEP/repos/oneplanner/pull-requests?state=OPEN
To check status to particular PR:
curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests/{pr-id}
DOC https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm8287391664
Paged APIs
Bitbucket uses paging to conserve server resources and limit response size for resources that return potentially large collections of items. A request to a paged API will result in a values array wrapped in a JSON object with some paging metadata, like this:
{
"size": 3,
"limit": 3,
"isLastPage": false,
"values": [
{ /* result 0 */ },
{ /* result 1 */ },
{ /* result 2 */ }
],
"start": 0,
"filter": null,
"nextPageStart": 3
}
Clients can use the limit and start query parameters to retrieve the desired number of results.
The limit parameter indicates how many results to return per page. Most APIs default to returning 25 if the limit is left unspecified. This number can be increased, but note that a resource-specific hard limit will apply. These hard limits can be configured by server administrators, so it's always best practice to check the limit attribute on the response to see what limit has been applied. The request to get a larger page should look like this:
http://host:port/context/rest/api-name/api-version/path/to/resource?limit={desired size of page}
For example:
https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits?limit=1000
The start parameter indicates which item should be used as the first item in the page of results. All paged responses contain an isLastPage attribute indicating whether another page of items exists.
Important: If more than one page exists (i.e. the response contains "isLastPage": false), the response object will also contain a nextPageStart attribute which must be used by the client as the start parameter on the next request. Identifiers of adjacent objects in a page may not be contiguous, so the start of the next page is not necessarily the start of the last page plus the last page's size. A client should always use nextPageStart to avoid unexpected results from a paged API. The request to get a subsequent page should look like this:
http://host:port/context/rest/api-name/api-version/path/to/resource?start={nextPageStart from previous response}
For example:
https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits?start=25

Use Container Metrics from Prometheus

I deployed Prometheus on my cluster as well as cAdvisor and Grafana. It works tremendously well. I get all the data I need on Grafana's UI.
I started using Prometheus Java API in order to use this data. For example get the CPU usage and if it has a certain value something will be done.
What I display on Grafana is the Container CPU usage for each container. Now I would like to get that information with the Java API if possible (or something if not). But of course the PromQL queries aren't usable from a Java program (from what I tried but I may be wrong).
I thought of several ways:
Clone the cAdvisor project and directly implement what I want to do in Go
Create a bash script with the docker stat command that would get me the container and CPU usage associated
Or maybe there is actually a way to send PromQL queries.
For instance we get the metric by its name via Java or the Prometheus interface:
ex: node_cpu would get me some data.
But if I want something more precise, I need to send a request, for example irate(node_cpu{job="prometheus"}[5m]) which is not possible via Java.
Is there a way for me to get more precise metrics ?
Prometheus supports REST API requests, which are language-agnostic. You just need to send an HTTP request with your query and process the response.
see an example below, copied from their site.
the following HTTP GET request:
http://localhost:9090/api/v1/query?query=up&time=2015-07-01T20:10:51.781Z
returns something like this:
{
"status" : "success",
"data" : {
"resultType" : "vector",
"result" : [
{
"metric" : {
"__name__" : "up",
"job" : "prometheus",
"instance" : "localhost:9090"
},
"value": [ 1435781451.781, "1" ]
},
{
"metric" : {
"__name__" : "up",
"job" : "node",
"instance" : "localhost:9100"
},
"value" : [ 1435781451.781, "0" ]
}
]
}
}
lots more details, here

In what case would Neo4J's Rest API return a 404 Not Found?

I'm writing a batch job to POST to /db/data/batch in Neo4J a la the documentation here: http://docs.neo4j.org/chunked/2.0.4/rest-api-batch-ops.html.
I'm creating a Node via a POST operation, then creating a relationship via POST from a previously existing node, to the one created in the batch. Neo4J returns a 404 - Not Found on the relationship URL for the previously existing Node.
Here's the request:
[ {
"method" : "POST",
"to" : "/node",
"id" : 0,
"body" : {
"entityType" : "TimeOff",
"start" : "2014-08-13",
"end" : "2014-08-13",
"status" : "Approve",
"reqId" : 13579
}
}, {
"method" : "POST",
"to" : "/node/1234/relationships",
"id" : 1,
"body" : {
"to" : "{0}",
"type" : "REQUEST"
}
}
]
If I repeat this via SSH and cURL, it works without issue. Same database server, and same application server. The 404 seems to result from "/node/1234/relationships", even though cURL GETs to "/node/1234" and "/node/1234/relationships/all" work fine, as well as a POST via cURL.
I feel like there is something wrong with the server that is causing a 404, maybe due to a time-out or similar. Is this possible?
Probably better is to use the new transactional endpoint, and do Cypher statements, see http://docs.neo4j.org/chunked/stable/rest-api-transactional.html
MATCH (n)
WHERE id(n) = 1234
WITH n
CREATE (node:TimeOff{reqId:1234}) -[:REQUEST]->(n)

Resources