submitting a parameterized hudson build via the REST API - hudson

hudson supports submitting a build by doing an HTTP GET to an API. I need to pass some parameters to such a build. Just adding them as additional URL parameters doesn't work for me. Is this supposed to work? Is there some other mechanism?

Is it possible to pass parameters in the Hudson's job that will be triggered remotely?
Check this question.
Instead of /build use /buildWithParameters. I'm currently using it with a simple wget

Based on the HTML source on the web interface for starting a parameterized build, you need to do a POST to http://hudson/job/NAME/build with the parameters.
Update: It's a little more complicated. There's a hidden input with name "name" and value "MyParameter", then the input you actually fill in with name "value" and value "MyInput". (Where MyParameter if your parameter name and MyInput is whatever you need to fill in.) I haven't checked to see how this works with more than one parameter.
the POST works with just the json url parameter that contains a JSON list of the build parameters: json=%7B%22parameter%22%3A+%5B%7B%22name%22%3A+%22Input%22%2C+%22value%22%3A+%22data1%22%7D%2C+%7B%22name%22%3A+%22Input2%22%2C+%22value%22%3A+%22data2%22%7D%5D%2C+%7D

Related

How to pass both parameter and JSON in one single HTTP request body with having JSON a variable [JMeter]

I have a similar but extended question for the below question.
How to pass parameter and json both in http request request body in jmeter??
I will take the same example as mentioned in the above question/link.
Have to pass multiple parameters,
UserId=47
meeting={
"DeviceID":${deviceID},
"NetworkCarrierName":"VODAFONEIN",
"BatteryValue":"22",
"AppVersion":"1.1.3",
}
As you can see, DeviceID have a value from variable deviceID. I want to pass all these parameters and JSON in one single http request body.
What would be the approach for this?
In parameter I have to add the variable for value part for whichever key I want to refer to. It will work fine.
This image shows that..
The same approach will work fine, you can use JMeter Variables anywhere in your test plan, if there is a User Defined Variable or a pre-defined variable or a variable coming from a Post-Processor - JMeter will substitute the variable placeholder with its respective value in the runtime:
If you're uncertain regarding how to properly build your request the easiest is just recording it using HTTP(S) Test Script Recorder

How to make Simple-JSON variable template query in grafana?

I am trying to create a dynamic variable for a graph using a kdb+ database, which requires the Simple-JSON plug in. However, I am struggling to figure out how to write the query in the Query search bar under Variables on my Dashboard.
I have looked into the documentation found here but there is only a few mentions of the templating feature for variables in grafana, but nothing on how to do it.
https://github.com/grafana/simple-json-datasource/blob/master/README.md
You can write arbitrary text in the timeserie query, it doesn't need to be one of the hardcoded metrics that /search returns.
There is also the simpod json datasource plugin.
https://grafana.com/grafana/plugins/simpod-json-datasource
built on top of the Simple JSON Datasource. It has refactored code, additional features and active development.
One of the "additional features" is an "Additional JSON Data" tab where you can use variables. {"key": $variableValue}
It actually turns out that the adaptor for kdb+/grafana needs it's search function overloaded to be able to accept variables and return a string (or something that grafana can understand).

Groovy to generate dynamic parameters based on JSON of job values?

I just found that Jenkins jobs via a JSON URL each job has using this format: https://jenkinsurl.net/job/_test/lastBuild/api/json provides info like below.
{"_class":"hudson.model.FreeStyleBuild","actions":[{"_class":"hudson.model.ParametersAction","parameters":[{"_class":"hudson.model.StringParameterValue","name":"build_num","value":""}]},{"_class":"hudson.model.CauseAction","causes":[{"_class":"hudson.model.Cause$UserIdCause","shortDescription":"Started by user anonymous","userId":"anonymous","userName":"anonymous"}]},{},{},{},{},{},{"_class":"org.jenkinsci.plugins.buildenvironment.actions.BuildEnvironmentBuildAction"},{}],"artifacts":[],"building":false,"description":null,"displayName":"#1","duration":1850,"estimatedDuration":1850,"executor":null,"fullDisplayName":"_test #1","id":"1","keepLog":false,"number":1,"queueId":5753,"result":"SUCCESS","timestamp":1479700053274,"url":"http://jenkinsserver.net/job/_test/1/","builtOn":"node_name","changeSet":{"_class":"hudson.scm.EmptyChangeLogSet","items":[],"kind":null},"culprits":[]}
I'd like to know how I can query those fields with a Groovy script to help me build Dynamic parameters when selecting "Build with Parameters". I already have the Groovy and Dynamic parameter plugins and use them for some simple queries I've been using to generate some parameters, like timestamps not overwritten by Jenkins jobs downstream.
How do I query for these and return their values? For example, if I wanted to return the value of the user that started the build from this segment:
[{"_class":"hudson.model.Cause$UserIdCause","shortDescription":"Started by user anonymous","userId":"anonymous","userName":"anonymous"}]
This isn't a question about getting the person that triggered the build. Sorry if that's not such a great example, but this one appears to be a bit nested, so presumably a good one to learn with.
I know how to reference the value of parameters and get some info to return to generate them, but not how to use that URL and extract specific info from it to help create a parameter's value before the build begins. Is this possible? If not, what other mechanism could I use?
You can do something similar to this one:
How do I discover the additional causes of my Jenkins build?
job = hudson.model.Hudson.instance.getItem("demo-job")
build = job.getLastBuild()
// get action first
def action = build.getAction(hudson.model.CauseAction.class)
cause = action.findCause(hudson.model.Cause.UserIdCause)
println cause.userId
http://javadoc.jenkins-ci.org/hudson/model/Cause.UserIdCause.html
The question is abit confusing so not sure if this helps at all. Anyway, you should be able to extract all the information you need from build returned by getLastBuild().
It not possible to extra parameters before the build begins. If that is what you mean.

insert a new document json using http post apache solr

What I have: Apache Solr 5.2.1
What I want: add a new document in a specific core defined by me
example: address of the solr core -->
http://IP_ADDRESS:8984/solr/myCustom_core/
I want to add a document json formed by {"id":"00001","title":"my title"} to the core above directly from the browser's url bar.
Problem:
I'm trying to address this problem in such a way:
http://IP_ADDRESS:8984/solr/myCustom_core/update?wt=json&{add:{"id":"00001","title":"my title"}}&commit=true
The response of the browser is:
{"responseHeader":{"status":0,"QTime":88}}
However, when I check on the server side the new entry is not added.
Conversely,it is works if I try to add such a document using the submit command provided in the UI of Solr.
Can someone provide me the correct way to build the correct url address?
Thanks
EDIT: thanks to MatsLindh I solved my problem using this:
http://IP_ADDRESS:PORT/solr/myCustom_core/update?stream.body=<add><doc><field name="exampleField">example value</field></doc></add>&commit=true
You can use stream.body to send an arbitrary content stream through GET variables instead of using POST (or a regular body).
Be sure to perform appropriate escaping of the content you use in your URL.
You'll also have to perform a commit before the submitted content becomes searchable, either through commit=true in the request or by issuing a separate commit request.

JBPM rest calls with JSON

We want to start a process in JBPM6 using the rest API. We need to pass an object as a process variable.
We know how to do it JAXB and the execute call. But we want to do it with JSON and /runtime/{deploymentId}/process/{processDefId}/start
Is it possible? we try and have no success.
I am not sure whether my answer exactly addresses the question. But for someones use in future I place couple of lines here.
If you want to set a process variable when starting a process using the RESTful API, you can do it like this.
If your variable name is myVar just add the value as a URL parameter by appending the phrase "map_" to the parameter name. It means the parameter name should now be map_myVar. For an example see below request.
http://<host>:<port>/jbpm-console/rest/runtime/{deploymentId}/process/{processDefId}/start?map_myVar=myValue
You can confirm whether the value is set by writing below code in a script task.
Object var = kcontext.getVariable("myVar");
System.out.println("myVar : " + var);
See the 17.1.1.3. Map query parameters section of JBPM6 documentation.
After talking to the dev that is responsible for the REST API. I was able to confirm how it works.
The
/runtime/{deploymentId}/process/{processDefId}/start
Is a POST request where all the contents in the payload are ignored. The variables are written as key=value in the GET string.
With deployment id: com.web:work:1.0
With processDefId: work.worload
2 variables: var1 and var2
For example:
/runtime/com.web:work:1.0/process/work.worload/start?var1=a&var2=b
I'm still after trying to understand how to define objects with the remote API.
Meanwhile, I also confirmed that it is impossible to define objects using this way. The only way to define objects is only by using the JaxB. This uses the "/execute" path