groovy

Gradle command line arguments to override properties in build.gradle

杀马特。学长 韩版系。学妹 提交于 2021-02-08 13:33:17
问题 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

Groovy - Define variable where the variable name is passed by another variable

淺唱寂寞╮ 提交于 2021-02-08 11:23:23
问题 I want define a variable in groovy with where the variable name is passed by another variable. Something like. def runExtFunc(varName){ def varName // => def abc varName = load 'someFile.groovy' // abc = load 'someFile.groovy' varName."$varName"() // -> abc.abc() (run function defined in File) } [...] runExtFunc('abc') // -> abc.abc() (Function abc defined in File) [...] runExtFunc('xyz') // -> xyz.xyz() (Function xyz defined in File) [...] Sadly def varName defines the variable varName and

Dynamic variable in Jenkins pipeline with groovy method variable

♀尐吖头ヾ 提交于 2021-02-08 08:01:34
问题 I have a Jenkinsfile in Groovy for a declarative pipeline and two created Jenkins variables with names OCP_TOKEN_VALUE_ONE and OCP_TOKEN_VALUE_TWO and the corresponding values. The problem comes when I try to pass a method variable and use it in an sh command. I have the next code: private def deployToOpenShift(projectProps, environment, openshiftNamespaceGroupToken) { sh """/opt/ose/oc login ${OCP_URL} --token=${openshiftNamespaceGroupToken} --namespace=${projectProps.namespace}-$

jenkins pipeline def new string parameter

◇◆丶佛笑我妖孽 提交于 2021-02-08 07:27:31
问题 I have a parameterized job with pipeline. for example: Predefined String Parameter: IP I'm trying to define a new String in the pipeline in order to use it as a new parameter when I'm calling to another "build job" I have tried the following method: import hudson.model.* node('master'){ if(ipaddr =='192.168.1.1'){ def parameter = new StringParameterValue("subnet", '255.255.255.0') //not working echo parameter //not working } stage ('Stage A'){ build job: 'jobA', parameters: [ [$class:

Set headers in a groovy post request

谁说胖子不能爱 提交于 2021-02-07 22:49:13
问题 I need to set a header in a post request: ["Authorization": request.token] I have tried with wslite and with groovyx.net.http.HTTPBuilder but I always get a 401-Not authorized which means that I do cannot set the header right. I have also thought of logging my request to debug it but I am not able to do that either. With wslite this is what I do Map<String, String> headers = new HashMap<String, String>(["Authorization": request.token]) TreeMap responseMap def body = [amount: request.amount]

Set headers in a groovy post request

允我心安 提交于 2021-02-07 22:48:19
问题 I need to set a header in a post request: ["Authorization": request.token] I have tried with wslite and with groovyx.net.http.HTTPBuilder but I always get a 401-Not authorized which means that I do cannot set the header right. I have also thought of logging my request to debug it but I am not able to do that either. With wslite this is what I do Map<String, String> headers = new HashMap<String, String>(["Authorization": request.token]) TreeMap responseMap def body = [amount: request.amount]

encoder function for multipart/form-data in groovy

心已入冬 提交于 2021-02-07 20:30:33
问题 I need to form a 'multipart/form-data' REST request with jpeg image and JSON file as the content.I am stuck with encoding the 'multipart/form-data' as a zip file. Can someone tell me, how I can achieve this with groovy RESTClient? I could not find any documentation regarding this. 回答1: As it can be seen in the docs RESTClient extends HTTPBuilder . HTTPBuilder has a getEncoder method that can be used to add dedicated encoder (with type and method). See the following piece of code: import org

Compile groovy script statically with command line arguments

不问归期 提交于 2021-02-07 19:38:14
问题 I am trying to statically compile a groovy script to speed up it's execution, but am not able to get it to work if command line arguments are used. My actual script is much longer, but the one-line script I use for this question perfectly reproduces my error. Using the following script ( test.groovy ) println(args.length) This can be compiled with the command groovyc test.groovy and ran by the java command java -cp .;%GROOVY_HOME%\lib\* test and will simply print the number of command line

Call top level function from groovy method

我们两清 提交于 2021-02-07 13:30:55
问题 I figure this has a simple answer, but my web searching couldn't find it. If I've got the following (ideone): def f() {} class C { public h() { f() } } x = (new C()).h(); This fails with the following error: No signature of method: c.f() is applicable for argument types: () values: [] How do I call f() from inside a method of C ? 回答1: You need a reference to the "outer" class (which isn't really an outer class). Assuming you are writing your code in a Script.groovy file, it generates two

Call top level function from groovy method

戏子无情 提交于 2021-02-07 13:29:05
问题 I figure this has a simple answer, but my web searching couldn't find it. If I've got the following (ideone): def f() {} class C { public h() { f() } } x = (new C()).h(); This fails with the following error: No signature of method: c.f() is applicable for argument types: () values: [] How do I call f() from inside a method of C ? 回答1: You need a reference to the "outer" class (which isn't really an outer class). Assuming you are writing your code in a Script.groovy file, it generates two