groovy

Unable to connect to oracle database from groovy

£可爱£侵袭症+ 提交于 2021-02-10 09:29:50
问题 Hi i am unable to connect to oracle database in groovy . I have used the following code in groovy console but getting the following compilation error unable to resolve class oracle.jdbc.driver.OracleTypes at line: 5, column: 1 I have used the following code import java.sql.Connection import java.sql.DriverManager import javax.sql.DataSource import groovy.sql.Sql import oracle.jdbc.driver.OracleTypes sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:databasename", "username", "password",

Jenkins groovy MissingMethodException No signature of method

会有一股神秘感。 提交于 2021-02-10 06:15:23
问题 I am facing getThingsDone() is applicable for argument types: () values: [] error for code as below, in shared library .... vars/pipeline.groovy def getThingsDone(m = null){ echo "done" } in some project that includes shared library @Library(shared_pipeline@branch_name) _ pipeline.getThingsDone() I tried with defining getThingsDone(...) without any arguments with string arguments with Map arguments Nothing works. So I want to get a function that accepts no parameter(s) up and running. But it

Exporting and Importing Jenkins Pipeline script approvals

泄露秘密 提交于 2021-02-09 11:53:09
问题 I have a significant set of Groovy pipeline scripts for our Jenkins build process. I am in the process of moving those scripts onto another instances, and would like to replicate the set of approved scripts that were not originally white listed. Is it possible to export the list of approved signatures and import them into another instance? The only other solution I have is to constantly run and rerun the scripts and approving each signature as it breaks the build. Since the scripts are quite

Fetch only keys from JSON Object using groovy

匆匆过客 提交于 2021-02-09 02:53:54
问题 This is my JSON Object { "master": { "node": "xyz", "files": [{"type": "modified", "file": "test.txt"}] }, "testbranch2": { "node": "abc", "files": [{"type": "modified", "file": "test.txt"}] }, "testbranch": { "node": "xxx", "files": [{"type": "modified", "file": "test.txt"}], } } I need only the object key names, like "master", "testbranch2","testbranch. How do I fetch only the object key names using groovy? 回答1: You can use JsonSlurper import groovy.json.JsonSlurper def json = '{ "master":

Fetch only keys from JSON Object using groovy

扶醉桌前 提交于 2021-02-09 02:48:17
问题 This is my JSON Object { "master": { "node": "xyz", "files": [{"type": "modified", "file": "test.txt"}] }, "testbranch2": { "node": "abc", "files": [{"type": "modified", "file": "test.txt"}] }, "testbranch": { "node": "xxx", "files": [{"type": "modified", "file": "test.txt"}], } } I need only the object key names, like "master", "testbranch2","testbranch. How do I fetch only the object key names using groovy? 回答1: You can use JsonSlurper import groovy.json.JsonSlurper def json = '{ "master":

No such DSL method 'pipeline' found among steps

不羁岁月 提交于 2021-02-08 14:59:57
问题 I keep getting this error for the declarative pipeline script in Jenkins. No such DSL method 'pipeline' found among steps My script is like this pipeline { agent any stages { stage('Example Build') { steps { echo 'Hello World' } } } } I have Jenkins version 2.19.4. Hopefully i have installed all the required plugins. Why do i get this exception ? 回答1: I think you have installed the latest plugins, 1.2. I had the same issue that after I upgraded the Pipeline: Model Definition to 1.2 my

Change XML tag name

孤街浪徒 提交于 2021-02-08 13:56:19
问题 I want to transform an XML document which I have parsed with XmlSlurper . The (identical) XML tag names should be replaced with the value of the id attribute; all other attributes should be dropped. Starting from this code: def xml = """<tag id="root"> | <tag id="foo" other="blah" more="meh"> | <tag id="bar" other="huh"/> | </tag> |</tag>""".stripMargin() def root = new XmlSlurper().parseText(xml) // Some magic here. println groovy.xml.XmlUtil.serialize(root) I want to get the following:

GPathResult to String without XML declaration

烂漫一生 提交于 2021-02-08 13:48:23
问题 I'm converting GPathResult to String using def gPathResult = new XmlSlurper().parseText('<node/>') XmlUtil.serialize(gPathResult) It works fine, but I'm getting XML declaration in front of my XML <?xml version="1.0" encoding="UTF-8"?><node/> How can I convert GPathResult to String without <?xml version="1.0" encoding="UTF-8"?> at the beginning? 回答1: Use XmlParser instead of XmlSlurper : def root = new XmlParser().parseText('<node/>') new XmlNodePrinter().print(root) Using new XmlNodePrinter

Determine if a task is defined in an external build.gradle file

时光总嘲笑我的痴心妄想 提交于 2021-02-08 13:43:23
问题 I have a gradle task that is created at runtime to call another task ("myOtherTask") which is in a separate gradle file. The problem is if that other task doesn't exist an exception will be thrown. Is it possible to check that a task exists in an external gradle file before attempting to call it? Example: task mainTaskBlah(dependsOn: ':setupThings') task setupThings(){ //... createMyOtherTask(/*...*/) //... } def createMyOtherTask(projName, appGradleDir) { def taskName = projName + 'blahTest'

Gradle command line arguments to override properties in build.gradle

让人想犯罪 __ 提交于 2021-02-08 13:33:47
问题 Whenever an existing android project is imported, in most cases we need to change values following with our installed tools version number in project/build.gradle buildscript { ... dependencies { classpath 'com.android.tools.build:gradle:x.x.x' } } in project/app/build.gradle android { compileSdkVersion xx buildToolsVersion "xx.x.x" defaultConfig { applicationId "com.example.app.xyz" minSdkVersion xx targetSdkVersion xx versionCode x versionName "x.x" } ... } dependencies { compile fileTree