Jenkins remote API - trigger job with static pulldown paramters - json

I am attempting to trigger a Jenkins build remotely via curl that has required parameters. These parameters are in the form of a static pull down.
I am able to trigger the build remotely via curl, but the parameters are not being passed - it appears that it is just taking the first (default) from each pull down.
Here is the curl command:
export json="{\"parameter\": [{\"name\": \"ENV\", \"value\": \"dev-1\"},{\"name\": \"PLATFORM\", \"value\": \"desktop\"},{\"name\": \"PRODUCT\", \"value\": \"Test\"}]}"
curl -H ".crumb:xxxxxxxxxxxxxxxxxxxxxx" -X POST http://server:8080/job/job_name/buildWithParameters -d token=tokenId --data-urlencode json="$json"
From what I can tell the JSON is valid - is there a different set of elements required for a static pull down list?
Thanks!

Use http://server:8080/job/job_name/build instead of buildWithParameters, as shown in the example for using the remote access api.
I'm not sure what's the reason for the difference, and it was a bit confusing for me at first, but when using buildWithParameters you need to add the parameters to the url as you found out with your wget command - and at the same time you can also add parameters when using the normal build trigger.
Note that when you trigger a build this way, it will still work if you leave out some parameters, but for those the default value won't be used (they will be unspecified).

I got this to work using wget instead of curl, but I'd still be interested in knowing how to make this work with curl if anyone has pointers.
This command works:
wget --delete-after --auth-no-challenge --http-user=${userID} --http-password=${authToken} http://server:8080/job/job_name/buildWithParameters?token=runme\&ENV='dev-1'\&PLATFORM='desktop'\&PRODUCT='Test'

Related

salt state to run JSON API

I am quite new to SALT, I need to query a JSON API through slat state, may I know how best I should do. I am trying below is of no help though.
Salt ‘*’ cmd.run ‘curl --insecure -u "username:password" -X POST -H "Content-Type: application/json" -d '{"action":"RouterName","method":"methodname","data":[{"limit":100000, "uid" : "Query UID"}],"tid":1}' https:///zport/dmd/device_router’
Can I use any state file to query JSON API of my application through SALT.
There is a difference between module and state.
Modules: Module runs the command/function every time and does not care if the task needs to be run or not.
State: On the other hand, the state cares about the status of the task that needs to be executed. Based on the result, it decides if the task should be run or the system is in the desired state that the task wants it to be.
More about this issue this.
To somehow answer your question, you cannot be sure what is the state of a server that you are trying to curl from. That means, that you need to use a module to get the current output and decide upon that.

Curl Post or Node/Express server converting double quotes to single quotes

I am sending a POST request from curl like this:
curl -H 'Content-Type:application/json" -X POST -d '{"key":"value"}' http://localhost:3000/parsejson
However, I am getting on my Node/Express server:
{'key':'value'} // req.body
So it is unclear to me if it is the curl request or the configuration of my node server. On my node server, I'm using: bodyParser.json() and bodyParser.urlencoded()
Thank you!
First of all this line is incorrect and you cannot run curl with that:
curl -H 'Content-Type:application/json" -X POST -d '{"key":"value"}' http://localhost:3000/parsejson
I'm mentioning it because this is a question about single and double quotes and you have single and double quotes messed up in your example of how you make a request, resulting in a code that cannot possibly be executed. Since this is obviously not how you really make the request, it is not clear how you do.
Now, if you want to see what you really get in the request, then don't use a body parser (temporarily switch it off, remove or comment it out) and run req.pipe(process.stdout) to display the request body on the server. Then you will know what you are getting from the client.
Also run curl with the -v option to see what it is actually sending.
If it turns out that curl is sending a correct JSON and your server gets a correct JSON in the request body then your problem must be somewhere else than in topics that you are asking about in this question.
Of course it's impossible to tell you what is the problem in that case because you didn't include even a single line of code in your question.

HTTP request error from running Postman Collection tests with Newman?

I've been using the new commandline for Postman, Newman, and have been attempting to run Collection tests that work fine when I pass them through the packaged app Jetpacks add-on, but do not run properly in the commandline. Although the json Collection file that I am passing does contain the proper header declarations, I don't have any other clues at this point, so I suspect that this may be an HTTP header issue. But I am not sure exactly what is wrong, as I am rather new to using Postman.
The tests that I'm trying to run are on some calls to an ASP.Net web API, very simple server response-checking one-line javascript tests like the ones in this tutorial.
A sample line that I enter into the console:
$ newman -c collectionfile.json -e environmentfile.json -n 5
achieves such a result:
RequestError: [token] terminated. Error: undefined
Any suggestions/help would be appreciated.
I ran into this problem as well and spent quite a few hours trying to figure it out. Eventually I realized that an address such as "www.google.com" will work in the chrome plugin UI, but not in Newman. For it to work in Newman, the address must be "https://www.google.com". Also, make sure that you have your data file (if you are using variables like {{url}}) set up correctly. You can use "-d dataFile.json" to define a data file. More information on that here.

BOX-API: Trying to get a shared folder without a token 401 Unauthorized error

I want to interrogate a shared folder without having to log the user in, from reading the documentation, this should be fine to do, but if run the example within my command line:
curl https://api.box.com/2.0/shared_items \
-H "Authorization: BoxAuth api_key=YOUR_API_KEY&shared_link=https%3A%2F%2Fwww.box.com%2Fs%2F8tqjqtoky18sbnoz264c"
Using my API key it works fine, however, within my app or just within a web browser, if I use:
https://api.box.com/2.0/shared_items -H "Authorization: BoxAuth api_key=YOUR_API_KEY&shared_link=https%3A%2F%2Fwww.box.com%2Fs%2F8tqjqtoky18sbnoz264c"
again with my API key, I get 401 Unauthorized error.
What am I doing wrong? Is it an encoding issue? as it looks like the end part of the string needs to be encoded, however the rest of it doesn't, I have tried to make sure that the C# code I am using does not encode the string, and I think it is not, but it still fails with 401.
It looks like the shared link from the example that you're using (the one ending with 8tqjqtoky18sbnoz264c) is no longer a valid URL. You should go into the Box web app and create a new shared link to test with, and that should work.

REST how to handle query parameters when put to resource?

I have a REST data service where I want to allow the users to create new items with HTTP PUT using different formats like json,xml,csv. I'm unsure how to best handle the format specification in the url:
PUT /ressource/ID/json
PUT /ressource/ID/xml
or
PUT /ressource/ID?format=json
PUT /ressource/ID?format=xml
So what is the best way to specify a format indicator?
If I specify the format with an query parameter and want to do a PUT how can I do this with curl?
curl -T test/data.json -d "format=json" http://localhost:5000/resource/33
does not work.
curl -T test/data.json http://localhost:5000/update?format=json
works, but I would rather let curl build the query parameters instead of adding them by myself.
A general principle of RESTful web services is to use the features built-in to HTTP, when applicable. In this case, you can indicate the format of your PUT request's content by setting the Content-Type header to application/json or application/xml.