update Jenkins build parameter via remote API - jenkins

I am looking for a method to remotely update a build parameter for a Jenkins jobs after the job has started (or even after the job has completed perhaps).
Looking over the API docs, I have seen plenty of examples of doing a GET to retrieve information, and some examples of doing a POST to trigger build configurations to run.
I'm struggling to find any examples or information on whether it's possible to set information such as a parameter via API, e.g. using POST.

Related

How can we enable/disable a Azure DevOps Pipeline using Azure Devops rest api or CLI commands

I'm trying to enable/disable multiple pipelines based on a condition, would like to create a pipeline that takes the parameter from the user and updates all the other pipelines.
I've found these below documents from Microsoft
https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines?view=azure-devops-rest-6.0
https://learn.microsoft.com/en-us/cli/azure/ext/azure-devops/pipelines?view=azure-cli-latest
but I'm not able to find anything for enabling/disabling a pipeline, is there any way of doing this in any other ways?
I'm not able to find anything for enabling/disabling a pipeline, is there any way of doing this in any other ways?
You can use the REST API Definitions - Update to enable or disable pipelines.
PUT https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=6.0
For its request body, you need to get the definition of the build using the GET REST API first:
GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=6.0
Use the response body of GET REST API as the request body of PUT REST API. And then modify the value of queueStatus according to your requirements.
If you want to enable the pipeline, set the value of queueStatus to enabled; If you want to disable the pipeline, set the value of queueStatus to disabled.

How to get all running builds for current user in jenkins api?

I know how to get all builds from a specific job and know how to get the list of builds from the current user in the Jenkins UI by going to https://jenkins.${domain}.com/user/${username}/builds, however, there doesn't seem to be an API for that specific address because if you go to https://jenkins.${domain}.com/user/${username}/builds/api it comes up with a 404.
Is there a way via the api to query all of the builds for a specific user?

how to get json response for build details from Jenkins build after it finishes

I have a Jenkins Server which runs a Jenkins job - JobA
and I have a Java Spring boot web service, where I store the Jenkins build data and serve it to various other systems.
I want that whenever JobA finishes each build, it should call an endpoint on my web service and post the build data (bascically the same data that I get from calling the Jenkins API: https://<my-jenkins-server>/job/JobA/<buildNumber>/api/json) to the end point of my web service, which accepts a POST requests and JSON payload to update the build details like job name, build number, build result, build url, build duration, timestamp, test results etc. in my database.
The endpoint of my web service should still be called even if the build fails.
I can already get all this data from the above REST API call, but I do not want to use that because, using that if I want to get the updated data in my database, I will have to poll the Jenkins REST API multiple times, (like maybe every 15 minutes or more frequently) which will increase the load on my Jenkins server.
I know that I can set up a Jenkins job to either call a script or call another downstream job through which I can then call a curl POST request to my end point.
But my problem is that I do not know where/how to get the JSON data for the build be sent in the POST request?
Can someone help me out please?
You can get the lastbuild information and there is a field called building which says if the build is running or not.
https://host/job/project/lastBuild/api/json?depth=1

Jenkins. How to get Trigger builds remotely data from POST BODY

Jenkins. How to get Trigger builds remotely data from POST BODY
Quay.io (private docker containers registry) has notification about build status through Webhook POST, data is in body. I tried to google and read Jenkins docs, but found only how to read parameters from URL.
I found a plugin (Generic Webhook Trigger), which is capable to do it partially. It is able to work only with one link (http://{JENKINS_URL}/generic-webhook-trigger/invoke). And to start different jobs i need to use regexp.
At the same time i need to set up minimum 3 notifications on quay.io and a lot of webhooks from different services. Maybe somebody knows how to set up in Jenkins such stuff:
Create route like {JENKINS_URL}/jobName/ …
Take whole parameters and write it down into $POST_DATA variable.
Execute script with $POST_DATA parameter.
Another manipulations i’m able to do myself in script.
If you have a job like some-job-name.
Question 1:
Check the "Trigger builds remotely". Specify a token, like some-job-name.
Point the webhook to http://{JENKINS_URL}/generic-webhook-trigger/invoke?token=some-job-name .
Now this will be the only job triggered from this request.
Question 2:
Set the json-path to just $ and it will evaluate to the entire post data. Use any variable like variable.
Question 3:
Just use the variable from 2 like $variable.

Dashboard using output results from Jenkins API

I am new to Jenkins API. I just had assignement in company where PL asked me to create a new job in Jenkins where I will run all the testing,build related things on my code and it should create dashboard where all figures and graph should be shown. He said that its feasible. Can anyone please guide me to do so.
Checkout Sectioned-Vew-Plugin.
Create a Job on Jenkins and add /api after the Url. You could see the API Information related to the Job you have just created. The API will contain the Get End points for Retrieving the data. Its available in JSON as well as XMl which you can parse and use as the source of Info for your dashboard. You can also trigger a new Build by using the Post API.

Resources