How to put a zip file to server with JMeter? - file

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.

Related

How can I upload a file to zookeeper (solr configset synonyms.xml file) using curl / rest API?

I'm trying to upload a file into my solr's configset folder stored in zookeeper. I'm hoping to do this from a rather limited serverless function on Azure, which does not have access to Java or the zookeeper command line client. After researching for a bit, it looks like there is no HTTP way to copy a file to zookeeper - is this correct? How can I, if it's possible, upload a file to zookeeper with HTTP?
The body of the request should be a zip file that contains the configset. The zip file must be created from within the conf directory (i.e., solrconfig.xml must be the top level entry in the zip file).
Here is an example on how to create the zip file named "myconfig.zip" and upload it as a config set named "myConfigSet":
$ (cd solr/server/solr/configsets/sample_techproducts_configs/conf && zip -r - *) > myconfigset.zip
$ curl -X POST --header "Content-Type:application/octet-stream" --data-binary #myconfigset.zip "http://localhost:8983/solr/admin/configs?action=UPLOAD&name=myConfigSet"
Please refer the solr Documentation

download multiple files from sftp with Jenkins

I have to download all files from a ftp folder using Explicit FTP over SSL/TLS. I need that for a jenkins job, running on a windows machine and didnt find any plugins - so I am trying to use a batch script with curl and the following code lists the contents of the folder.
set "$FILEPATH=C:\temp"
set "$REMOTEPATH=/files/"
curl -u user:pass --ftp-ssl ftp://hostame.com:port%$REMOTEPATH% -o %$FILEPATH%
I figured out that with curl I have to download files one by one, but how can I achieve to go through all the files in a ftp directory and get them one by one?
Is there a better way to achieve that? I read about mget, but it doesnt seem to work with the explicit ftp over ssl.
Thanks
I couldnt bring it to work with batch directly in the script, so I wrote a python script instead and download it from git and execute it as a step in the pypeline. It has some nice libraries, so it works as a charm.

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"}'

PUT with cURL couchDB

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?

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"

Resources