How to fix "No such DSL method 'agent' found among steps"? - jenkins-pipeline
I am trying to execute a portion of my script in a docker container.
...
stage ("run test") {
agent {
docker {
label "docker"
image "dyalog/dyalog"
}
}
steps {
....
However, Jenkins gives an error message that is not helpful (at least for me):
java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [acceptGitLabMR, addEmbeddableBadgeConfiguration, addGitLabMRComment, archive, bat, build, catchError, checkout, compareVersions, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, echo, emailext, emailextrecipients, envVarsForTool, error, exws, exwsAllocate, fileExists, findFiles, getContext, getHighestSemanticVersion, getNextSemanticVersion, git, gitChangelog, gitlabBuilds, gitlabCommitStatus, influxDbPublisher, input, isUnix, junit, library, libraryResource, load, lock, mail, milestone, node, nodesByLabel, parallel, powershell, prependToFile, properties, publishChecks, publishHTML, pwd, pwsh, readCSV, readFile, readJSON, readManifest, readMavenPom, readProperties, readTrusted, readYaml, resolveScm, retry, script, setGitHubPullRequestStatus, sh, sha1, sha256, sleep, sshagent, stage, stash, step, svn, tar, tee, timeout, timestamps, tm, tool, touch, unarchive, unstable, unstash, untar, unzip, updateGitlabCommitStatus, validateDeclarativePipeline, verifySha1, verifySha256, waitUntil, warnError, withChecks, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeCSV, writeFile, writeJSON, writeMavenPom, writeYaml, ws, zip] or symbols [GitUsernamePassword, Number, Open, all, allBranchesSame, allOf, allowRunOnStatus, always, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, architecture, archiveArtifacts, artifactManager, asIsGITScm, attach, authorizationMatrix, batchFile, bitbucketServer, booleanParam, branch, branchCreated, branches, brokenBuildSuspects, brokenTestsSuspects, buildButton, buildDiscarder, buildDiscarders, buildParameter, buildRetention, buildSelector, buildUser, buildingTag, builtInNode, caseInsensitive, caseSensitive, certificate, changeRequest, changelog, changeset, checkoutToSubdirectory, choice, choiceParam, cleanWs, clock, close, command, commentPattern, commit, commitChanged, commitMessagePattern, configFile, configFileProvider, contributor, copyArtifactPermission, copyArtifacts, copyartifact, created, credentials, cron, crumb, culprits, default, defaultFolderConfiguration, defaultView, deleted, demand, description, developers, disableConcurrentBuilds, disableResume, docker, dockerCert, dockerServer, dockerTool, dockerfile, downstream, dumb, durabilityHint, email-ext, envInject, envVars, envVarsFilter, environment, equals, executor, expression, extendedEmailPublisher, exwsGlobalConfigurationDiskPools, exwsGlobalConfigurationTemplates, exwsNodeConfigurationDiskPools, fastestReadSpeed, fastestWriteSpeed, file, fileParam, filePath, fingerprint, fingerprints, frameOptions, freeStyle, freeStyleJob, fromDocker, fromScm, fromSource, ftpPublisher, git, gitBranchDiscovery, gitHub, gitHubBranchDiscovery, gitHubBranchHeadAuthority, gitHubEvents, gitHubExcludeArchivedRepositories, gitHubExcludeForkedRepositories, gitHubExcludePublicRepositories, gitHubForkDiscovery, gitHubIgnoreDraftPullRequestFilter, gitHubPRStatus, gitHubPlugin, gitHubPullRequestDiscovery, gitHubSshCheckout, gitHubTagDiscovery, gitHubTopicsFilter, gitHubTrustContributors, gitHubTrustEveryone, gitHubTrustNobody, gitHubTrustPermissions, gitLabConnection, gitParameter, gitTagDiscovery, gitUsernamePassword, github, githubBranches, githubPRAddLabels, githubPRClosePublisher, githubPRComment, githubPRMessage, githubPRRemoveLabels, githubPRStatusPublisher, githubPlugin, githubProjectProperty, githubPullRequests, githubPush, gitlab, globalConfigFiles, hashChanged, headRegexFilter, headWildcardFilter, hyperlink, hyperlinkToModels, inheriting, inheritingGlobal, installSource, isRestartedRun, javadoc, jdk, jdkInstaller, jgit, jgitapache, jnlp, jobBuildDiscarder, jobName, junitTestResultStorage, label, labels, labelsAdded, labelsExist, labelsNotExist, labelsPatternExists, labelsRemoved, lastCompleted, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, lastSuccessful, lastWithArtifacts, latestSavedBuild, legacy, legacySCM, list, local, location, logRotator, loggedInUsersCanDoAnything, mailer, masterBuild, maven, maven3Mojos, mavenErrors, mavenGlobalConfig, mavenMojos, mavenWarnings, message, modernSCM, mostUsableSpace, msbuild, msbuildError, msbuildWarning, myView, namedBranchesDifferent, newContainerPerStage, noGITScm, node, nodeProperties, nodejs, nodejsci, nonInheriting, nonMergeable, none, not, organizationFolder, overrideIndexTriggers, paneStatus, parallelsAlwaysFailFast, parameters, password, pattern, permalink, permanent, pipeline, pipeline-model, pipeline-model-docker, pipelineTriggers, plainText, plugin, pollSCM, preserveStashes, projectNamingStrategy, proxy, pruneTags, pullRequest, pullRequests, queueItemAuthenticator, quietPeriod, rateLimit, rateLimitBuilds, recipients, requestor, resourceRoot, restriction, restrictions, retainOnlyVariables, run, runParam, sSHLauncher, schedule, scmRetryCount, scriptApproval, scriptApprovalLink, search, security, shell, simpleBuildDiscarder, skipDefaultCheckout, skipStagesAfterUnstable, slave, sourceRegexFilter, sourceWildcardFilter, specific, ssh, sshPublicKey, sshUserPrivateKey, standard, status, statusOnPublisherError, string, stringParam, suppressAutomaticTriggering, suppressFolderAutomaticTriggering, swapSpace, tag, tags, teamSlugFilter, text, textParam, timestamper, timestamperConfig, timezone, tmpSpace, toolLocation, triggeredBy, unsecured, untrusted, upstream, upstreamDevelopers, userSeed, usernameColonPassword, usernamePassword, viewsTabBar, weather, withAnt, workspace, x509ClientCert, zip] or globals [currentBuild, docker, env, params, pipeline, scm]
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:219)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
at jdk.internal.reflect.GeneratedMethodAccessor666.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:158)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:48)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
at jdk.internal.reflect.GeneratedMethodAccessor596.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:95)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Finished: FAILURE
To the (admittedly, my) uneducated brain this seems to indicate that agent is not accepted following stage - but I have applied similar constructs w/o issues before, so I do not understand what the issue is here.
I was able to solve this by restructuring the script a bit (removing earlier steps).
I'm still puzzled this helped and am still worried about an environment that leaves its user as much in the dark as $#% Jenkins does with its useless error message, but hey, it's working! ;)
Related
How to escape ${} in Jenkins configuration as code (casc) plugin?
I am using Jenkins configuration as code (CASC) plugin to create Jenkins job during server startup inside docker. I wrote a shell script as a step inside a job configuration. - script: > freeStyleJob('jenkins-job-sample') { description('Sample') triggers { githubPush() } scm { git { remote { url('${GIT_URL}') credentials('github-credentials') } branch '*/dev' extensions {localBranch('dev')} } } steps { shell(""" do cat \$OUTPUT | while read line || [[ -n \$line ]]; do CAPP_ENTRY=\$line GROUP_ID_PATH=(\${CAPP_ENTRY[0]}) ARTIFACT_ID=(\${CAPP_ENTRY[1]}) VERSION=(\${CAPP_ENTRY[2]}) done done """) } publishers { } } After the job is created I want the final script step to be shown as below. CAPP_ENTRY=\$line GROUP_ID_PATH=(${CAPP_ENTRY[0]}) ARTIFACT_ID=(${CAPP_ENTRY[1]}) VERSION=(${CAPP_ENTRY[2]}) But during server startup it throws the following error. org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: script: 31: unexpected char: '\' # line 31, column 34. GROUP_ID_PATH=(\) ^ 1 error at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150) at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120) at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132) at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350) at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:139) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234) at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at groovy.lang.GroovyShell$parse.call(Unknown Source) at javaposse.jobdsl.dsl.AbstractDslScriptLoader.parseScript(AbstractDslScriptLoader.groovy:134) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174) at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:101) It seems that ${CAPP_ENTRY[0]} is getting evaluated before the job creation happens which results to be (\). I want to escape ${} from getting evaluated before job creation. I tried in below ways. GROUP_ID_PATH=(\${CAPP_ENTRY[0]}) GROUP_ID_PATH=(\$\{CAPP_ENTRY[0]}) GROUP_ID_PATH=(\"${CAPP_ENTRY[0]}\") None of the above worked. Highly appreciate any suggestions on how I can escape it from getting evaluated.
Found an answer. Adding a ^ solved my issue. :) (^${CAPP_ENTRY[0]}) Source: https://github.com/jenkinsci/configuration-as-code-plugin/issues/577
I have had the same issue, and so far havent found "the" solution however for a workaround I just break the string e.g. instead of def HOSTS_LOCATION = "../bootstrap/inventory/${ENVIRONMENT_MAP[params.region]}_aws_ec2.yaml" I do def HOSTS_LOCATION = "../bootstrap/inventory/" + ENVIRONMENT_MAP[params.region] + "_aws_ec2.yaml"
Predecessor didn't know VCS
So, I have a long list of folders that I need to import into a VCS (probably git). Has anyone any suggestions how to automate this process? 2016_09_02_Backup 2017_04_24_Backup 2018_10_23_001_WarExport 2016_09_08_Backup 2017_04_24_WarExport 2018_10_23_002_WarExport 2016_09_09_Backup 2017_06_26_Backup 2018_10_23_003_WarExport 2016_09_09_WarExport 2017_06_26_WarExport 2018_10_23_004_WarExport 2016_09_12_WarExport 2017_06_30_Backup 2018_10_23_005_WarExport 2016_09_13_WarExport 2017_06_30_WarExport 2018_10_23_006_WarExport 2016_09_14_WarExport 2017_07_11_Backup 2018_10_23_007_WarExport 2016_09_15_WarExport 2017_07_12_Backup 2018_10_23_008_WarExport 2016_09_16_WarExport 2017_07_13_Backup 2018_10_23_009_WarExport 2016_09_19_WarExport 2017_08_21_Backup 2018_10_24_001_WarExport 2016_09_20_WarExport 2017_08_21_WarExport 2018_10_24_002_WarExport 2016_09_22_Backup 2017_10_05_Backup 2018_10_24_003_WarExport 2016_09_22_WarExport 2017_10_05_WarExport 2018_11_22_001_WarExport 2016_09_26_Backup 2018_08_13_WarExport 2018_11_22_002_WarExport 2016_09_27_Backup 2018_08_14_WarExport 2018_11_29_Backup 2016_09_27_WarExport 2018_08_15_001_WarExport 2018_11_29_WarExport 2016_11_10_Backup 2018_08_15_002_WarExport 2018_12_12_Backup 2016_11_10_WarExport 2018_08_15_003_WarExport 2018_12_12_WarExport 2016_12_22_Backup 2018_08_15_004_WarExport 2019_04_10_WarExport 2016_12_23_Backup 2018_08_15_005_WarExport 2019_05_07_WarExport 2017_01_02_Backup 2018_08_15_006_WarExport 2019_05_27_WarExport 2017_01_31_Backup 2018_08_15_007_WarExport 2019_06_14_WarExport 2017_02_23_Backup 2018_08_15_Backup 2019_07_15_WarExport 2017_02_23_WarExport 2018_09_26_001_WarExport 2019_08_09_001_WarExport 2017_02_27_Backup 2018_09_26_002_WarExport 2019_08_09_002_WarExport 2017_02_27_WarExport 2018_10_11_WarExport 2019_08_09_003_WarExport 2017_03_13_Backup 2018_10_16_WarExport 2019_08_12_002_WarExport 2017_03_13_WarExport 2018_10_18_Backup 2019_08_12_003_WarExport 2017_03_30_Backup 2018_10_19_001_WarExport 2019_08_12_WarExport 2017_03_30_WarExport 2018_10_19_002_WarExport 2019_08_14_WarExport 2017_04_03_Backup 2018_10_19_003_WarExport 2020_04_28_Current 2017_04_03_WarExport 2018_10_22_WarExport Every folder has about the same structure (code files, project settings etc) just evolving over time.
Not able to import com.paytm.merchant.CheckSumServiceHelper when running beanshell script in jmeter
I am new to Jmeter's JSR223 PreProcessor. We have just integrated Paytm's payment gateway into our product and we had to run load tests using Jmeter. We have to generate a checksum using a set of values and then inject that into our Json payload. I am using Java Beanshell to execute the code. I have added the jar file available here in my bin directory and also added it to my class path before starting the tests. Here is what my code looks like: import com.paytm.merchant.CheckSumServiceHelper; com.paytm.merchant.CheckSumServiceHelper checkSumServiceHelper = com.paytm.merchant.CheckSumServiceHelper.getCheckSumServiceHelper(); TreeMap<String,String> parameters = new TreeMap<String,String>(); String merchantKey = "xxxxxxxxxxxxxxxxx"; parameters.put("MID", "xxxxxxxxxxxxxxxxxxxxxx"); parameters.put("ORDERID", "${orderId}"); parameters.put("TXNID", "20200113111212800110168201701179744"); parameters.put("TXN_AMOUNT", "10.01"); parameters.put("PAYMENTMODE", "DC"); parameters.put("CURRENCY", "INR"); parameters.put("TXNDATE", "2020-01-13 13:59:03.0"); parameters.put("STATUS", "TXN_SUCCESS"); parameters.put("RESPCODE", "01"); parameters.put("RESPMSG", "Txn Success"); parameters.put("GATEWAYNAME", "HDFC"); parameters.put("BANKTXNID", "777001911059826"); parameters.put("BANKNAME", "JPMORGAN CHASE BANK"); parameters.put("BANKNAME", "JPMORGAN CHASE BANK"); String checkSum = checkSumServiceHelper.genrateCheckSumGAE(merchantKey, parameters); vars.put("checkSum", checkSum) Here is the error I am getting as a result: javax.script.ScriptException: Sourced file: inline evaluation of: ``import com.paytm.merchant.CheckSumServiceHelper; com.paytm.merchant.CheckSumSer . . . '' : Typed variable declaration : Class: com.paytm.merchant.CheckSumServiceHelper not found in namespace : at Line: 3 : in file: inline evaluation of: ``import com.paytm.merchant.CheckSumServiceHelper; com.paytm.merchant.CheckSumSer . . . '' : com .paytm .merchant .CheckSumServiceHelper in inline evaluation of: ``import com.paytm.merchant.CheckSumServiceHelper; com.paytm.merchant.CheckSumSer . . . '' at line number 3 at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:93) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19] at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19] at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) ~[java.scripting:?] at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:225) ~[ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:44) [ApacheJMeter_components.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:935) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:537) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.1.1 r1855137] at java.lang.Thread.run(Thread.java:830) [?:?] Any kind of help to resolve this error will be highly appreciated. It might be a stupid question but I am new to this so please help!! :) EDIT: I am now using the groovy syntax for doing this. I am not able to view my checksum variable in View Results Tree with my debug sampler but I am able to see it in the console. The value is shown correctly in console. But the variable is not being exported. import com.paytm.pg.merchant.CheckSumServiceHelper; com.paytm.pg.merchant.CheckSumServiceHelper checkSumServiceHelper = com.paytm.pg.merchant.CheckSumServiceHelper.getCheckSumServiceHelper(); TreeMap parameters = new TreeMap(); String merchantKey = "xxxxxxxxxxxxxxxxx"; parameters.put("MID", "xxxxxxxxxxxxxxxxxxxxxx"); parameters.put("ORDERID", "${orderId}"); parameters.put("TXNID", "20200113111212800110168201701179744"); parameters.put("TXN_AMOUNT", "10.01"); parameters.put("PAYMENTMODE", "DC"); parameters.put("CURRENCY", "INR"); parameters.put("TXNDATE", "2020-01-13 13:59:03.0"); parameters.put("STATUS", "TXN_SUCCESS"); parameters.put("RESPCODE", "01"); parameters.put("RESPMSG", "Txn Success"); parameters.put("GATEWAYNAME", "HDFC"); parameters.put("BANKTXNID", "777001911059826"); parameters.put("BANKNAME", "JPMORGAN CHASE BANK"); parameters.put("BANKNAME", "JPMORGAN CHASE BANK"); String checkSum = checkSumServiceHelper.genrateCheckSumGAE(merchantKey, parameters); Out. println "s====================================ssssss" OUT. println checkSum props.put("checkSum", checkSum); Here is the error when I run this: javax.script.ScriptException: javax.script.ScriptException: java.security.InvalidKeyException: Invalid AES key length: 17 bytes I think this error is due to my input values.
Beanshell is not Java and it isn't 100% compliant with Java, you need to stick to Java 1.5 language level in general. In particular Beanshell doesn't support Diamond Operators, you need to remove them from your code like: TreeMap parameters = new TreeMap(); In general starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting, the reasons are in: Groovy scripts can be compiled and cached while Beanshell is being evaluated each time it's called hence Groovy performance is much higher Groovy supports all underlying JDK language features while Beanshell got stuck at Java 5 In addition Groovy provides a lot of enhancements over normal Java SDK Check out Apache Groovy - Why and How You Should Use It article for more details.
Getting Content is not allowed in prolog when running in Java
I am facing Content is not allowed in prolog exception when I run my xxx.jmx file from Java (Jmeter 5.0). I tested the jmx in the GUI mode and everything works fine and in the Java I am just following the standard way to call the jmx file and execute it. The jmx just have some normal stuff. Sending HTTP request and validate the expected and received XML (I am using this snipped to validate): import org.apache.commons.io.FileUtils expect = FileUtils.readFileToString(new File('some_path')) XmlParser parser = new XmlParser() expectedXML = new XmlSlurper().parseText(expect) actualXML = new XmlSlurper().parseText(prev.getResponseDataAsString()) if (expectedXML != actualXML) { AssertionResult.setFailure(true) AssertionResult.setFailureMessage('Mismatch between expected and actual XML \n'+ prev.getResponseDataAsString()) and the stack trace: 2018/10/24 15:18:03,386 12675 [ERROR ] [Thread Group 1-1] (JSR223Assertion.java:52) – Problem in JSR223 script: Validate resposne javax.script.ScriptException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) at javax.script.CompiledScript.eval(CompiledScript.java:92) at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:221) at org.apache.jmeter.assertions.JSR223Assertion.getResult(JSR223Assertion.java:49) at org.apache.jmeter.threads.JMeterThread.processAssertion(JMeterThread.java:901) at org.apache.jmeter.threads.JMeterThread.checkAssertions(JMeterThread.java:892) at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:565) at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) at java.lang.Thread.run(Thread.java:745) Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at groovy.util.XmlSlurper.parse(XmlSlurper.java:207) at groovy.util.XmlSlurper.parse(XmlSlurper.java:260) at groovy.util.XmlSlurper.parseText(XmlSlurper.java:286) at groovy.util.XmlSlurper$parseText.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at Script1.run(Script1.groovy:9) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ... 10 more UPDATE 1: The problem of using Response Assertion is it cannot ignore the space or tab. So if the format is not exactly the same when I use equal will always fail. Any ideas how to ignore these things by using Response Assertion? UPDATE 2: I found out that the issue is not related to the BOM. Is becasue if I run the jmx from my Java application: prev.getResponseDataAsString() above function always return: ${__FileToString(${inputFilePath},,)} but not the actual response. This function is come from the body data of the HTTP Request sampler!!!!!! If I give the acutal body there then I am able to run the jmx...... Any idea how to deal with this dynamic body data?
It might be the case your "expected" XML file contains BOM and it causes your code failure. BOM is basically 3 first bytes so you can remove them using code like: def expect = FileUtils.readFileToString(new File('some_path')).getBytes().flatten() 1.upto(3) { expect.remove(0) } XmlParser parser = new XmlParser() def expectedXML = parser.parseText(new String(expect.toArray(new Byte[0]))) The rest of your code should work fine. Check out The Groovy Templates Cheat Sheet for JMeter article to learn more Groovy tips and tricks. Also be informed that in majority of cases it's easier to use Response Assertion or when it comes to XML - XPath Assertion, Java code will work faster than Groovy in any case.
How to connect to Oracle DB with slick 3.0.1?
I'm starting to learn and experiment with slick. I'm trying to connect to an oracle dev database, set up by our DBA. However i am encountering issue and i can't connect. Here is what i did so far: oracledev = { url = "jdbc:oracle:thin:#//vdevdbms2:4208/TPSDEV.IADB.ORG" driver = com.typesafe.slick.driver.oracle.OracleDriver connectionPool = disable keepAliveConnection = true } I have the following in my build resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/maven-releases/" libraryDependencies ++= Seq( "com.smartlogic.osclient" % "Semaphore-OS-Client" % "Semaphore-3.7.2", "com.typesafe.slick" %% "slick-extensions" % "3.1.0", "org.slf4j" % "slf4j-nop" % "1.6.4" ) The code so far is simply: object SlickSpike extends App { val db = Database.forConfig("oracledev") } I get the following error: Exception in thread "main" java.lang.ClassNotFoundException: disable at java.lang.ClassLoader.findClass(ClassLoader.java:530) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at slick.util.ClassLoaderUtil$$anon$1.loadClass(ClassLoaderUtil.scala:12) at slick.jdbc.JdbcDataSource$.loadFactory$1(JdbcDataSource.scala:30) at slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:39) at slick.jdbc.JdbcBackend$DatabaseFactoryDef$class.forConfig(JdbcBackend.scala:268) at slick.jdbc.JdbcBackend$$anon$3.forConfig(JdbcBackend.scala:33) at SlickSpike$.delayedEndpoint$SlickSpike$1(SlickSpike.scala:16) at SlickSpike$delayedInit$body.apply(SlickSpike.scala:14) at scala.Function0$class.apply$mcV$sp(Function0.scala:34) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App$$anonfun$main$1.apply(App.scala:76) at scala.App$$anonfun$main$1.apply(App.scala:76) at scala.collection.immutable.List.foreach(List.scala:381) at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35) at scala.App$class.main(App.scala:76) at SlickSpike$.main(SlickSpike.scala:14) at SlickSpike.main(SlickSpike.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) If i remove the line: ** connectionPool = disable ** Then i get the following error: Exception in thread "main" java.lang.ClassNotFoundException: slick.jdbc.hikaricp.HikariCPJdbcDataSource$ at java.lang.ClassLoader.findClass(ClassLoader.java:530) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at slick.util.ClassLoaderUtil$$anon$1.loadClass(ClassLoaderUtil.scala:12) at slick.jdbc.JdbcDataSource$.loadFactory$1(JdbcDataSource.scala:30) at slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:35) at slick.jdbc.JdbcBackend$DatabaseFactoryDef$class.forConfig(JdbcBackend.scala:268) at slick.jdbc.JdbcBackend$$anon$3.forConfig(JdbcBackend.scala:33) at SlickSpike$.delayedEndpoint$SlickSpike$1(SlickSpike.scala:16) at SlickSpike$delayedInit$body.apply(SlickSpike.scala:14) at scala.Function0$class.apply$mcV$sp(Function0.scala:34) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App$$anonfun$main$1.apply(App.scala:76) at scala.App$$anonfun$main$1.apply(App.scala:76) at scala.collection.immutable.List.foreach(List.scala:381) at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35) at scala.App$class.main(App.scala:76) at SlickSpike$.main(SlickSpike.scala:14) at SlickSpike.main(SlickSpike.scala) What am I doing wrong ? I would simply like, to have a connection pool of 10, and connect to the database but i have no idea of how to set it up. Can someone help ? Edit2 I solve the initial issue but i still have question and can't get everything to work. I change my build as such: libraryDependencies ++= Seq( "org.slf4j" % "slf4j-api" % "1.7.13", "org.slf4j" % "slf4j-simple" % "1.7.13", "com.smartlogic.osclient" % "Semaphore-OS-Client" % "Semaphore-3.7.2" exclude("org.slf4j","slf4j-log4j12"), "com.typesafe.slick" %% "slick" % "3.1.0", "com.typesafe.slick" %% "slick-extensions" % "3.1.0", "com.typesafe.slick" %% "slick-hikaricp" % "3.1.0", "com.oracle" % "ojdbc6" % "11.2.0.2.0" ) I resorted to add slick-hikaricp, even if I did not intent to use originally. Also I understood now that the oracle driver in the config, was the actual oracle drive, not the slick one. This is actually reflected in the change i did to my config as can be seen below: oracledev = { url = "jdbc:oracle:thin:#//vdevdbms2:4208/TPSDEV.IADB.ORG" driver = oracle.jdbc.OracleDriver // connectionPool = disable keepAliveConnection = true //databaseName = "BRIKPOOLPARTYDEV" user = "*******" password = "*******" } Questions: 1 - Is slick-hikaricp required by default when using Oracle. Indeed if i do not add it and comment out connectionPool = disable, which in my case, do not work when uncommented anyway, the program does not compile. 2 - I'm still not able to connect, am i missing something ? Please help
the oracle, db2, and ms sql drivers are not free. there is a separate 'slick-extensions' package that contains drivers for them that you can use for development. but you have to fork over cold cash for production use of them.
You should download and put the ojdbc7.jar in a folder in your root project (lib) and have it rebuilt.
The entry in the config for connectionPool should be disabled instead of disable. This config entry is used when deciding what JdbcDataSource will be loaded. The disable config entry tries to load a JdbcDataSourceFactoryfactory with the name disable.