I am using the Jenkins REST API to automate our CI process.
The last thing that is missing in the automatization pipeline is the creation of a view if theuser-defined view does not exist.
So far I used:
jenkins_alias/createView?name=My-Test-View
but it is somehow incomplete and returns the error that:
the viewtype should be defined
how can I define this viewtype from the RESTAPI? Should I send it in the Url or in the request body?
thanks
Per this post, this is apparently (a) possible with the REST API and (b) without referencing any weird Hudson stuff.
# create the view
curl -vvv -X POST -d #view.xml -H "Content-Type: text/xml" http://localhost:8080/createView?name=MyView
# get the configuration
curl http://localhost:8080/view/MyView/config.xml
# update the view
curl -X POST -d #view.xml -H "Content-Type: text/xml" http://localhost:8080/view/MyView/config.xml
Caveat emptor - I believe this is undocumented. According to the Jenkins REST API documentation, all the REST API can do is:
retrieve information from Jenkins for programmatic consumption
trigger a new build
create/copy jobs
Please try this request as an example:
curl -X POST -H 'Jenkins-Crumb:<JENKINS-CRUMB>' --form name=test --form mode=hudson.model.ListView --form json='{"name": "test", "mode": "hudson.model.ListView"}' https://<Jenkins-URL>/createView
View types:
ListView: hudson.model.ListView
Dashboard (if plugin Dashboard View is installed): hudson.plugins.view.dashboard.Dashboard
MyView: hudson.model.MyView
Related
I tried to update a variable for gitlab ci with
curl --request PUT --header "PRIVATE-TOKEN: $CI_TOKEN" "https://gitlab.com/mathmeier/landesrunde-nrw/api/v4/projects/1/variables/DATABASE_LIST" --form "value=$NEW_DB_LIST"
but my URL is obviously broken. From the description on the gitlab REST api pages, I do not understand how I construct the URL. Furthermore, I do not know what this project number or id should be.
Can anybody enlighten me?
You can get the project id from the main page of the project. Then the call would look something like this:
curl --request PUT --header "PRIVATE-TOKEN: $CI_TOKEN" "https://gitlab.com/api/v4/projects/37804337/variables/DATABASES_LIST" --form-string value=$NEW_DB_LIST
I have Dropwizard backend end and like to use curl to make a POST request with a Json body
I used Postman with the settings on the body tab raw radio button selected and on the drop down menu JSON(applicattion/json).I entered the body and was able to successfully create a POST request.
However when I used curl I get an error. I used
curl -v -X POST "localhost:8080/resource"
-H "Content-Type: application/json"
-d '{label1: "words1", label2: "words2"}'
I get the error message
{"code":400,"message":"Unable to process JSON"}
From my understanding it is curl that has an issue since Postman was able to create the POST request.
This
{label1: "words1", label2: "words2"}
is not JSON. Use
{"label1": "words1", "label2": "words2"}
I would like to allow anyone to trigger a job I've created in Rundeck.
I can't understand from the API documentation how to do that.
Any one knows, and can give simple examples (my understanding of the subject is minimal to none)?
What I've found is of the sort:
POST /api/1/job/[ID]/run
In order to use the Rundeck API, you need to authenticate first.
Authentication can be done in two different ways:
Using a Token
Using a username and a password
Here is an example of running a Rundeck job using its API (Token based authentication)
curl -X POST http://rundeck_server:port/api/19/job/87bdc26ce-9893-49bd-ad7a-97f4c4a39196/run?authtoken=AVy8jZdcpTYOyPcOVbfcfOQmB6b92zRu --header "Content-Type:text/xml"
Explanation:
19: the API version or Rundeck installation version (19 matchs
Rundeck 2.8.2)
87bdc26ce-9893-49bd-ad7a-97f4c4a39196: Job UUID
run: Runs a job
PS: To obtain an API Token, you must first log in to the Rundeck GUI using a user account. Click on your username in the header of the page, and you will be shown your User Profile page. From this page you can manage your API Tokens.
To update the answer above, this is an example of running a job and feeding it arguments
You will need to replace hostname/API version/job UID/token
Also the current version can be used with JSON only
curl -X POST https://rundeck-hostname.com/api/41/job/7087d3b7-e454-4983-abd5-a211d21d6f27/run?authtoken=[redacted] -H "Accept: application/json" -H "Content-Type: application/json" -d '{
"options": {
"optionName":"optionValue",
}
}
'
And if you need additional arguments for running a job you can find the updated documentation at https://docs.rundeck.com/docs/api/rundeck-api.html#running-a-job
I wanna write a groovy script to bulk update my job configuration using Jenkins REST API. But I am quite confused by its API doc (http://localhost:8080/jenkins/job/my_job_name/api/).
Fetch/Update config.xml
To programmatically obtain config.xml, hit this URL. You can also POST an updated config.xml to the same URL[http://localhost:8080/jenkins/job/my_job_name/config.xml] to programmatically update the configuration of a job.
How am I gonna POST an xml file to an url mentioned above?
The below curl command works for me.
curl --user $USER:$API_TOKEN -X POST http://localhost:8080/job/test/config.xml -H 'Content-Type: application/xml' --data-binary "#mymodifiedlocalconfig.xml"
curl -X POST -H 'Content-Type: application/octet-stream' http://<ip>/job/<job name>/config.xml --user uname:upass --data-binary #./test.xml
Many answers set Content-Type: application/xml, and it didn't work in my Jenkins. I try to set Content-Type: application/octet-stream and it work successfully.
I tried cURL and it worked.
curl -F "file=#updated_config.xml" "http://localhost:8080/jenkins/job/my_job_name/config.xml"
Note: U will need to toggle off "Prevent Cross Site Request Forgery exploits" in Jenkins config.
Trying to test Uber Rush API (from localhost and from linux server).
Calling Token works - I get the token
trying to implement sanbox example:
curl -X "PUT /v1/sandbox/deliveries/{delivery_id}" \
-H "Authorization: Bearer <OAUTH TOKEN>" \
-d "{\"status\":\"en_route_to_pickup\"}"
with url https://sandbox-api.uber.com/
and I tried the same request with file_get_contents (in PHP)
So, I always get error "405 Method Not Allowed"
{"message":"Method not supported for this endpoint.","code":"method_not_allowed"}
What I need to do to get access to method from this sandbox example https://developer.uber.com/docs/rush/sandbox?
Corrent syntax
curl -X "PUT" -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/DELIVERY_ID
EDIT: Updated to reflect both issues in your question...
You have a mismatch in your requests and an incorrect syntax for curl.
First off your CURL request is incorrectly specified. It should be:
curl -X "PUT" -H "Authorization: Bearer <OAUTH TOKEN>" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/{delivery_id}
In addition, your curl command is trying to issue a PUT request to the uber sandbox PUT API. However, your PHP code is not setting the context correctly and so is probably issuing a GET request. I suspect that the server is therefore rejecting the request as a GET as not allowed to do this sort of operation.
To fix it, see Bad request using file_get_contents for PUT request in PHP. This should give you an example of how to pass in the necessary context to issue a PUT request using file_get_contents().