PUT with cURL couchDB - database

I am trying to create a database with curl from the command line on Windows using this command:
curl -X PUT http://127.0.0.1:5984/test_database.
I receive this response:
curl: (52) Empty reply from server
I am able to see all the created databases (curl -X GET http://127.0.0.1:5984/_all_dbs) and i can also use GET to see information for a specific database created from Futon interface, but PUT doesn't seem to work.
I have also tried to enter the curl command from win-bash command line. I got the same response.
What else should i try?

Related

How to put a zip file to server with JMeter?

How to put a zip file to server with JMeter?
This is a sample curl command:
curl -i --noproxy '*' -H Content-Type:application/octet-stream -X PUT -T /home/eknoose/vmm/image/CXP2010034_2A-R2A893.zip http://10.62.49.229:8083/vmm/api/configuration/uploadImage/CXP2010034_2A-R2A893.zip
I want to execute a lot of this kind command with a different filename, how to write the http request in jmeter, I have to use put and not post.
How to construct such a HTTP request with JMeter?
Thanks
The relevant HTTP Request sampler configuration would be something like:
Content-Type header in its turn can be added using HTTP Header Manager
In general given you can successfully upload the file using curl you should be able to record the event using JMeter's HTTP(S) Test Script Recorder just make sure to:
Configure curl to use JMeter as the proxy
Copy the file(s) you will be uploading to the "bin" folder of your JMeter installation.

Using curl with AngularJS and bash

I’m trying to fill out web forms using curl via a bash script to a website that uses AngularJS. Can’t find any documentation on how to do this. Is it even possible to use curl to POST data to webforms that use AngularJS? I’m not even sure I’m asking the right question or if there’s a better method?
In most cases AngularJS uses ajax calls with JSON payload instead of old-school multipart POSTs.
You can use browser to send test post and save request information "as cURL".
Most likely you will have ready-to-use command to add to your bash file.
But quite often such posts are associated with authenticated person so you will need to fill in up-to-date session cookie into your request.
First things to check will be whether your command works with cleaned cookies.
If it works then your task is done.
Just call such API with something like this:
curl -X POST -H "Content-Type:application/json" \
http://some-server/handle-form \
-d '{"parameter1":["41","34"],"another_parameter":"val1"}'
But if your curl request is rejected by server with cookies absent then you need to setup proper cookie before invocation of API request.
This call will authenticate you against server and will store session cookie in a jar file:
curl -b ./jar -c ./jar -i -X POST -H "Content-Type:application/json" \
http://some-server/login \
-d '{"login":"my-user-name", "password":"my-password"}'
And such save session cookies would be reused for subsequent API calls:
curl -b ./jar -c ./jar -i -X POST -H "Content-Type:application/json" \
http://some-server/handle-form \
-d '{"parameter1":["41","34"],"another_parameter":"val1"}'

Retrieve latest artifact from JFROG artifactory

I have a few versions of my code in JFROG, which are provided to the clients. How do I specify a generic way to pull latest version(Artifact)? It is not Maven code. I looked up on the Jfrog page:
'''
GET http://localhost:8081/artifactory/ivy-local/org/acme/[RELEASE]/acme-[RELEASE].jar
'''
How do I get [RELEASE] ?
Please help ?
the [RELEASE] in this case is the version number you want to download the latest artifact for. To get that number you can use the REST API call for Artifact Latest Version Search Based on Layout. For example
GET /api/search/latestVersion?g=org.acme&a=artifact&repos=libs-snapshot-local
This would return a string of the latest release version you have.
You can follow the documentation at jfrog
#!/bin/bash
# Note that we don't enable the 'e' option, which would cause the script to
# immediately exit
set -uo pipefail
HOST=myartcloud.jfrog.io
USER=thisIsMyUser
PASS=thisismypass
SNAPSHOT_LAST_VERSION=$(curl --silent --show-error --fail \
-u$USER:"$PASS" \
-X POST https://$HOST/artifactory/api/search/aql \
-H "content-type: text/plain" \
-d 'items.find({ "repo": {"$eq":"my-repo-snapshot"}, "name": {"$match" : "my-project-package-name*"}})'\
| grep -E -o -e 'my-project-package-name-[[:digit:]].[[:digit:]].[[:digit:]]+'| uniq | sort | tail -1 \
| grep -E -o -e '[[:digit:]].[[:digit:]].[[:digit:]]+')
Explanation. Making usage of curl with option
--fail (HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts.
--silent Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
--show-error When used with -s it makes curl show an error message if it fails.
Then a post request -X POST is made using basic authentication to the api path. The content type of the request is -H "content-type: text/plain".
-d, --data (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML.
The data sent, is using a filter query to find an repository and also the content.
After the api results, using grep command line utility where it searches for PATTERNS and return only the version number.
Example: 0.1.1

Start Jenkins build using batch script

I am working with a Jenkins build server to run synthesis/simulation for FPGAs.
Right now I have nightly builds and can start the build manually in Jenkins browser interface.
My question is:
Is there any possibility to start a job build with a batch script without using browser interface?
(I am running Jenkins on Windows 7 64bit.)
Here is an example with a curl command (for a job with parameters):
curl -X POST -u YOUR_USER:YOUR_USER_PASSWORD http://YOUR_JENKINS_URL/job/YOUR_JOB/buildWithParameters?PARAM1=value1&PARAM2=value
And a job without parameters:
curl -X POST -u YOUR_USER:YOUR_USER_PASSWORD http://YOUR_JENKINS_URL/job/YOUR_JOB/build
If you don't want to use your user/password, you can generate an API token for your Jenkins user:
And use this token in your curl command:
curl -X POST http://YOUR_JENKINS_URL/job/YOUR_JOB/build?TOKEN=YOUR_API_TOKEN
You can trigger a Jenkins job with a configured token instead of your username/password, which would allow you to share a trigger script without exposing your own credentials.
Go to your job's configuration.
Scroll down to Build Triggers, and check the box for Trigger build remotely (e.g., from scripts), and enter an authentication token (e.g., "MY_TOKEN").
Copy one of the URLs below the Authentication Token field based on whether your build has parameters.
Then use that URL in a curl command to trigger a build. For example:
curl -I https://${JENKINS_URL}/job/tmp/job/dummy-test/build?token=MY_TOKEN
The -I parameter tells curl to print the head of the response, which you could use to determine the result status. Jenkins replies with HTTP 201 if successful:
$ curl -I https://<JENKINS_URL>/job/tmp/job/dummy-test/build\?token\=MY_TOKEN
HTTP/1.1 201 Created
Cache-Control: public
Content-Length: 0
Date: Mon, 11 Apr 2016 12:47:26 GMT
Location: https://<JENKINS_URL>/queue/item/1707/
Pragma: public
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
Connection: keep-alive
As I tried to trigger my job via curl I ended up always getting "Not authorized" errors.
Later I found out that this was because I completely disabled anonymous access on the server. The solution was to install the following plugin: https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin
Source: https://issues.jenkins-ci.org/browse/JENKINS-17764
you can do this using curl command with -I Option. create an API token for the jenkins Job and use it to trigger the job. you can use jenkins user password for this as well.
command would be
curl -I -u auto:<user_api_token> http://<jenkins_Server>/job/test/build?token=wefiytgwiefiweihfqweiodf
results would be
for more information
https://serverfault.com/questions/888176/how-to-trigger-jenkins-job-via-curl-command-remotely/888248#888248
In the new Jenkins Pipeline, under Build Triggers, select the checkbox Trigger builds remotely (e.g., from scripts). Then give Jenkins a token that will be required when triggering the build.
Not authorized errors
A problem with triggering the builds remotely is, if you've set up Jenkins right and disabled anonymous user access, you will get Not authorized errors when you try to trigger the build from a script (as #keocra pointed out). You now have two options:
Pass a username and password along when you trigger the build. This means that your script will need to include the username and password, which means everyone who can read your script will have the username and password, which is almost as bad as anonymous access.
Use the Build Token Root Plugin. This plugin allows you to use the Trigger builds remotely feature without requiring the username and password. All you need is the token you generated before.
Triggering the build
To trigger the build remotely, run
curl JENKINS_URL/buildByToken/build?job=JobFoo&token=MyToken
Where JENKINS_URL is the URL to your Jenkins instance, JobFoo is the name of your job, and MyToken is the token you entered under Trigger bulids remotely.
Of course, you don't need to use curl; you can also use wget or any other program that can make HTTP requests.
I've googled across many addresses and the working result can be found here:
#!/bin/bash
TOKEN='jenkins-user-token'
USER='my-username'
SERVER="http://your.server.address"
#jenkins job parameters
PARAMF=$1
SECONDPARAM=$2
# retrieve the crumb that we need to pass in the header
CRUMBS=$(curl -s -X GET -u $USER:$TOKEN ${SERVER}/crumbIssuer/api/json | jq -c '. | .crumb ')
curl --user $USER:$TOKEN -H "Jenkins-Crumb:${CRUMBS}" -X POST "${SERVER}/view/MyView/job/JobName/buildWithParameters?TOKEN=${TOKEN}&PARAMETERONE=${PARAMF}&PARAMETERTWO=${SECONDPARAM}"
The steps script does:
get the breadcrumb
call jenkins to execute a job with multiple parameters
you can save this script as jenkins-job-cli.sh and call it
chmod +x jenkins-job-cli.sh
./jenkins-job-cli.sh first-parameter second-parameter
Hope this help.
Cheers,
Leslie
Fast Forward to 2023
You need to pass 2 tokens to execute your job remotely from a script/bash.
You need:
apiToken to authenticate your identity. This value is created from JENKINS_URL/me/configure . Also check here for documentation
Another Job authentication token which you create when you enable 'Trigger builds remotely'.
Below is a sample to execute job with 2 parameters, you can tweak to get your done.
PARAM1_VALUE=<param1_value>
PARAM2_VALUE=<param2_vale>
USERNAME=dummy_user_name
JENKINS_URL="http://10.xxx.x.xxx:8080"
JOB_TOKEN="<value>" # you create this token when you enable Job>Configure>Build Triggers>Trigger builds remotely
LOGIN_API_TOKEN="<value>" #get this value from JENKINS_URL/me/configure
curl -L --user $USERNAME:$LOGIN_API_TOKEN "$JENKINS_URL/job/JobName/buildWithParameters?token=$JOB_TOKEN&param1_name=$PARAM1_VALUE&param2_name=$PARAM2_VALUE"

Solr curl connection failing using CURL

Im trying to use CURL to connect to SOLR db but my curl does not give any response...
curl -X GET 'http://localhost:8983/solr/#/collection1/select?q=*:*'
The web interface works very welll.
You should remove the fragment identifier (hash mark)
curl -X GET 'http://localhost:8983/solr/collection1/select?q=*:*'

Resources