I am trying to create bug in jire by using JMeter

Satish reddy May 16, 2023

By using JMeter jsr223 post processes I am trying to create ticket in Jira I have return some but that code is not working can any one help me to resolve the error is appreciated

Here is the code 

import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
def assertionResult = prev.getAssertionResults()[0]
if (assertionResult.isFailure()) {

// Set the JIRA REST API endpoint URL
String jiraUrl = "url";

// Set the JIRA account email and API token
String jiraEmail = "mailID";
String jiraApiToken = "Security token";

// Set the JSON payload for creating the JIRA ticket
String jsonPayload = """
{
"fields": {
"project": {
"key": "LEAR"
},
"summary": "Test issue",
"description": "This is a test issue",
"issuetype": {
"name": "Bug"
}
}
}
""";

// Set the HTTP headers for the JIRA REST API request
Map<String, String> headers = [:];
String authString = jiraEmail + ":" + jiraApiToken;
String encodedAuthString = authString.bytes.encodeBase64().toString();
headers.Put(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuthString);
headers.Put(HttpHeaders.CONTENT_TYPE, "application/json");

// Create an HTTP client and POST request
HttpClientBuilder builder = HttpClientBuilder.create();
HttpPost post = new HttpPost(jiraUrl);
post.setHeaders(headers);
post.setEntity(new StringEntity(jsonPayload));

// Execute the JIRA REST API request and get the response
def httpResponse = builder.build().execute(post);
def responseBody = httpResponse.getEntity().getContent().text;

// Log the response details
log.info("Response code: " + httpResponse.getStatusLine().getStatusCode());
log.info("Response body: " + responseBody);
}

 Thanks

3 answers

2 votes
Karim ABO HASHISH
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 17, 2023

hi @Satish reddy 

Welcome to the community.

Could you please share the error details to better assist you with a proper solution.

Awaiting your return.

Cheers,

Karim

Satish reddy May 17, 2023

2023-05-17 12:30:40,533 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2023-05-17 12:30:40,534 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2023-05-17 12:30:40,534 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2023-05-17 12:30:40,764 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2023-05-17 12:30:40,764 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2023-05-17 12:30:40,764 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2023-05-17 12:30:40,825 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor
javax.script.ScriptException: java.lang.ArrayIndexOutOfBoundsException: 0
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.7.jar:3.0.7]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.7.jar:3.0.7]
at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_202]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:45) [ApacheJMeter_components.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:955) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:573) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:5.4.3]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_202]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at org.codehaus.groovy.runtime.dgmimpl.arrays.ObjectArrayGetAtMetaMethod.invoke(ObjectArrayGetAtMetaMethod.java:41) ~[groovy-3.0.7.jar:3.0.7]
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.invoke(PojoMetaMethodSite.java:51) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139) ~[groovy-3.0.7.jar:3.0.7]
at Script62.run(Script62.groovy:11) ~[?:?]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.7.jar:3.0.7]
... 9 more
2023-05-17 12:30:40,826 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2023-05-17 12:30:40,826 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2023-05-17 12:30:40,826 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2023-05-17 12:30:40,827 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

Satish reddy May 17, 2023

2023-05-17 12:30:40,533 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2023-05-17 12:30:40,534 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2023-05-17 12:30:40,534 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2023-05-17 12:30:40,764 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2023-05-17 12:30:40,764 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2023-05-17 12:30:40,764 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2023-05-17 12:30:40,825 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor
javax.script.ScriptException: java.lang.ArrayIndexOutOfBoundsException: 0
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.7.jar:3.0.7]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.7.jar:3.0.7]
at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_202]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:45) [ApacheJMeter_components.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:955) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:573) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:5.4.3]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_202]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at org.codehaus.groovy.runtime.dgmimpl.arrays.ObjectArrayGetAtMetaMethod.invoke(ObjectArrayGetAtMetaMethod.java:41) ~[groovy-3.0.7.jar:3.0.7]
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.invoke(PojoMetaMethodSite.java:51) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139) ~[groovy-3.0.7.jar:3.0.7]
at Script62.run(Script62.groovy:11) ~[?:?]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.7.jar:3.0.7]
... 9 more
2023-05-17 12:30:40,826 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2023-05-17 12:30:40,826 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2023-05-17 12:30:40,826 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2023-05-17 12:30:40,827 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

Karim ABO HASHISH
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 21, 2023

hi @Satish reddy 

Please check parameters requirements when creating an issue using JIRA REST APIs. here you can find more info through this link. For example parameter "project" requires numeric value

Check also this Thread where you could find additional actions to help you resolve the script issue

Good Luck and let me know how it went for you.

Cheers,

Karim

0 votes
blazemeter October 7, 2023

This is not related to Jira by any means, the question should be asked in JMeter-related forums

There is an issue with your test logic.

JSR223 PostProcessor is exected before any Assertions hence prev.getAssertionResults() list is empty and getting first element of the empty list causes the exception you're getting.

Consider moving your logic into JSR223 Listener

More information:

0 votes
Satish reddy May 17, 2023

 

I am getting this error

 

 

 

2023-05-17 12:30:40,533 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2023-05-17 12:30:40,534 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2023-05-17 12:30:40,534 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2023-05-17 12:30:40,764 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2023-05-17 12:30:40,764 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2023-05-17 12:30:40,764 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2023-05-17 12:30:40,764 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2023-05-17 12:30:40,825 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor
javax.script.ScriptException: java.lang.ArrayIndexOutOfBoundsException: 0
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.7.jar:3.0.7]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.7.jar:3.0.7]
at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_202]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:45) [ApacheJMeter_components.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:955) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:573) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:5.4.3]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_202]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at org.codehaus.groovy.runtime.dgmimpl.arrays.ObjectArrayGetAtMetaMethod.invoke(ObjectArrayGetAtMetaMethod.java:41) ~[groovy-3.0.7.jar:3.0.7]
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.invoke(PojoMetaMethodSite.java:51) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139) ~[groovy-3.0.7.jar:3.0.7]
at Script62.run(Script62.groovy:11) ~[?:?]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.7.jar:3.0.7]
... 9 more
2023-05-17 12:30:40,826 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2023-05-17 12:30:40,826 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2023-05-17 12:30:40,826 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2023-05-17 12:30:40,827 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events