Difference between Groovy Binary and Source release?

A source release will be compiled on your own machine while a binary release must match your operating system. source releases are more common on linux systems because linux systems can dramatically vary in cpu, installed library versions, kernelversions and nearly every linux system has a compiler installed. binary releases are common on ms-windows systems. … Read more

Recommended way to stop a Gradle build

I usually throw the relevant exception from the org.gradle.api package, for example InvalidUserDataException for when someone has entered something invalid, or GradleScriptException for more general errors. If you want to stop the current task or action, and move on to the next, you can also throw a StopActionException

Groovy different results on using equals() and == on a GStringImpl

Nice question, the surprising thing about the code above is that println “${‘test’}”.equals(‘test’) returns false. The other line of code returns the expected result, so let’s forget about that. Summary “${‘test’}”.equals(‘test’) The object that equals is called on is of type GStringImpl whereas ‘test’ is of type String, so they are not considered equal. But … Read more

How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)?

With a declarative Jenkinsfile, you can use following pipeline: pipeline { agent any stages { stage (‘push artifact’) { steps { sh ‘mkdir archive’ sh ‘echo test > archive/test.txt’ zip zipFile: ‘test.zip’, archive: false, dir: ‘archive’ archiveArtifacts artifacts: ‘test.zip’, fingerprint: true } } stage(‘pull artifact’) { steps { copyArtifacts filter: ‘test.zip’, fingerprintArtifacts: true, projectName: env.JOB_NAME, … Read more

Converting a string to int in Groovy

Use the toInteger() method to convert a String to an Integer, e.g. int value = “99”.toInteger() An alternative, which avoids using a deprecated method (see below) is int value = “66” as Integer If you need to check whether the String can be converted before performing the conversion, use String number = “66” if (number.isInteger()) … Read more

Get values from properties file using Groovy

It looks to me you complicate things too much. Here’s a simple example that should do the job: For given test.properties file: a=1 b=2 This code runs fine: Properties properties = new Properties() File propertiesFile = new File(‘test.properties’) propertiesFile.withInputStream { properties.load(it) } def runtimeString = ‘a’ assert properties.”$runtimeString” == ‘1’ assert properties.b == ‘2’