groovy

JSON parsing using Groovy

我是研究僧i 提交于 2021-01-29 10:14:37
问题 I am trying to parse JSON records using Groovy script which is called through NiFi. Based on the input I got from Nested JSON with duplicate keys, it was working fine. But my groovy script got failed for few records if the value column has double quotes (") in it. E.g., "CT":"text/javascript; charset="UTF-8"" To fix the above issue, I replaced all the double quotes (") from the record and made the record look like, CT:text/javascript; charset=UTF-8 and used JsonParserType.LAX while parsing

Convert String to Map

五迷三道 提交于 2021-01-29 09:50:36
问题 def val = "[name: searchBaseDN value: , name: enable value: false, name: userDn value: cn=EAGREAD,ou=Users,ou=Administration,o=hyn, name: base value: , name: prefsize value: 1, name: timeBetweenEvictionRuns value: 300000]" I would like to convert it into hashmap val[name:value] Thanks for your help . 回答1: This looks promising: matches = val =~ /name:\s+(.*?)\s+value:\s+(.*?)(,\s+|\s+|])/ def newVal = [:] matches.each { m -> newVal[m[1]] = m[2] } But if the string is changed slightly, the

How to test a function which instantiate a variable from external call in Spock

走远了吗. 提交于 2021-01-29 09:22:28
问题 Hi I want to test below function using Spock framework private Connection getDBConnection() throws SQLException { DBClient client = DBService.getClient() String[] connInfo = client.getHistoryDBConnectInfo() String url = connInfo[1]; String user = connInfo[2]; String pwd = connInfo[3]; Connection conn; if(!StringUtils.containsIgnoreCase(url,"Authentication=ActiveDirectoryMsi")) conn = DriverManager.getConnection(url, user, pwd); else conn= DriverManager.getConnection(url); return conn; } Here

How to use Jenkins String Parameter in pipeline

不想你离开。 提交于 2021-01-29 07:57:41
问题 We am using Jenkins Pipeline to configure jobs in jenkins. For a bunch of jobs we need user input for which we use parameterised build where user can input parameter values and later we use the values in our .jenkinsfile in sh like sh "./build-apply.sh ${accountnumber} ${volumename} ${vpcname} services ${snapshotid}" This used to work with Jenkins 2.16 Pipeline 2.3 Groovy 2.15 However, when I rebuild Jenkins to: 2.16 or latest 2.26 Pipeline 2.5 Pipeline: Groovy 2.19 The above sh stopped

Merging a merge request using Gitlab API commands

大城市里の小女人 提交于 2021-01-29 07:25:41
问题 I'm trying to merge a merge request using the gitlab api and following is what I'm doing using groovy, but I keep hitting errors, I'm pretty new to this so any help is greatly appreciated! def MRUrl = "https://gitlab.domain.com/api/v4/projects/project_name/merge_requests/113/merge" def post = new URL(MRUrl).openConnection(); post.setRequestMethod("PUT") post.setDoOutput(true) post.setRequestProperty("Private-Token", "${Key}") post.getOutputStream().write(message.getBytes("UTF-8")); def

Parse date string without losing timezone in Groovy for Jira

半腔热情 提交于 2021-01-29 07:22:41
问题 I have date strings being created with different timezones, and I need to display them in a different format, but still showing each one's original timezone. I'm able to parse, but it parses to a unix timestamp, which then loses the original timezone. def dateCreated = issue.fields.created // 2018-12-21T10:20:00.483-0800 def dateParsed = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSSz", dateCreated) // 1545416400483 def dateFormatted = dateParsed.format('yyyy-MM-dd h:mm a, z') // 2018-12-21 6:20 PM,

How do I use unfolded list values to specify a vertex?

狂风中的少年 提交于 2021-01-29 06:12:40
问题 I'm trying to write a Gremlin traversal meaning "add all of these identities to this group", patterning it after the "inject list" example in the recipes. This is the logic I'm attempting: List identityIds = [...] gts.inject(identityIds).unfold() .V() // filter statement goes here? .addE(GROUP_INCLUDES_IDENTITY).from(V(groupId)) .iterate() As I understand it, this will spawn a traverser for each element in the list and execute the addE operation. However, I can't figure out how to express V()

How to add values in Jenkins dropdown parameter based on another params?

ε祈祈猫儿з 提交于 2021-01-29 06:01:05
问题 I want know how to add values to Jenkins dropdown parameter based another parameter value. I referred below link - Active Choices Reactive Reference Parameter in jenkins pipeline This is my Jenkins file #!groovy def date = new Date().format('MM/dd/yy').toString() properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [ [$class : 'ChoiceParameterDefinition',choices : 'master\nhotfix/18.3.0.35_Vol3',description: '',name: 'branchName'], [$class: 'ChoiceParameter', choiceType:

Gradle - Syntax error using plugin method with closure as argument

邮差的信 提交于 2021-01-29 04:50:54
问题 Below are two tasks hello & printProperties in build.gradle : task('hello', { description("Hey student! Run this one :D") group("Our demo") doLast({println("Hello World!")}) } ) plugins({ id('java') }) ext({ springVersion = "3.1.0.RELEASE" emailNotification = "build@master.org" }) sourceSets.all({ ext.purpose = null }) sourceSets({ main({ purpose = "production" }) test({ purpose = "test" }) plugin({ purpose = "production" }) }) task('printProperties', { doLast({ println(springVersion) println

Jmeter - declare array variable in one JSR223 Sampler in order to access it in another JSR223 Sampler

断了今生、忘了曾经 提交于 2021-01-28 22:45:07
问题 So I have 2 JSR223 samplers in Jmeter Thread Group. In the first one, I declare an empty array list import java.util.List; import java.util.ArrayList; myList = new ArrayList(); In the second JSR223 Sampler, that is inside ForEach Controller, I am trying to access myList variable in order to add some value import java.util.List; import java.util.ArrayList; myList.add(vars.get('trace_id')); I keep getting the message Response message: javax.script.ScriptException: groovy.lang