Skip to content

Instantly share code, notes, and snippets.

View ysb33r's full-sized avatar

Schalk W. Cronjé ysb33r

  • Andorra
View GitHub Profile
@ysb33r
ysb33r / Example.groovy
Last active June 26, 2023 23:43
Running Groovy unittests from the command-line
class Example {
def hhg() { 42 }
}
@ysb33r
ysb33r / RelativePath.groovy
Last active November 4, 2022 14:18
The Groovy way to obtain a relative path given two paths.
def root= new File('/usr/share')
def full= new File('/usr/share/docs/rpm-4.4')
// Print the relative path of 'full' in relation to 'root'
// Notice that the full path is passed as a parameter to the root.
def relPath= new File( root.toURI().relativize( full.toURI() ).toString() )
@ysb33r
ysb33r / build.gradle
Created May 17, 2014 09:53
HOWTO ignore spock tests when gradle is run offline
// Check whether --offline was passed to gradle and set it in the test configuration's system properties
test {
if(gradle.startParameter.isOffline()) {
systemProperties 'TESTS.ARE.OFFLINE' : '1'
}
}
@ysb33r
ysb33r / build-snippet.gradle
Created August 19, 2014 15:36
HOWTO control logging running tests from Gradle
// IN the build.gradle file
test {
systemProperties 'logback.configurationFile' : new File(projectDir,'src/test/resources/logback-test.xml').absolutePath
}
@ysb33r
ysb33r / JenkinsBuildFlowObjects.groovy
Last active October 1, 2016 19:24
If you are working with Jenkins BuildFlow plugin you can get some useful information of the returned build() call.
// Given that you have kicked off a build according to the DSL syntax
def results = build('RUN_THIS_JOB')
// Get out the name of the job again
println results.name
// Get the build ID
println results.id
// Get the build URL
// This is a workaround for the Grain plugin for Gradle
// It generates the Grain build into a subproject if one runs grainInstall
// It also elimnates the current way Grain drops stuff all over your build area.
// IN reality the Grain plugin needs a rewrite, but this is a workaround for now.
plugins {
id "com.sysgears.grain" version "0.2.3"
}
grain {
@ysb33r
ysb33r / CopyTaskAsAsGenerator.gradle
Last active February 28, 2016 21:57
Using a Gradle Task as a data-driven file generator
// Uses a single Groovy template and multiple sets of text input files.
// It generates a set of Groovy source files using the content of the text input files to set tokens within the
// template file.
task generateGroovySources( type : Copy ) {
from 'examples', {
include '*.txt'
}
into "${buildDir}/generated-src"
@ysb33r
ysb33r / JenkinsBuildFlowGetSVNTrackingInfo.groovy
Created August 13, 2013 14:00
Obtaining the SVN Tracking Plugin information from within a Jenkins Build Flow
// Assumuing that the build flow tracks another job's SVN revision
// Get the SVN URLs and revisions
def svn=build.getAction(hudson.scm.RevisionParameterAction.class)
svn.revisions.each {
println it.SVNURL
println it.revision
}
// Get the Build number of the job being tracked
@ysb33r
ysb33r / JenkinsBuildFlow.groovy
Last active December 19, 2015 01:19
An example of a more complex build flow in Jenkins.
def partitions=6
def testResults
def buildResult
def staticAnalysisResult
def smokeTestResult
def performanceResult
def buildFlow= { buildResult= build( 'BUILDER' ) }
def performanceFlow= { performanceResult = build('PERFORMANCE')}
@ysb33r
ysb33r / Download+Unpack.groovy
Created June 19, 2013 16:24
groovy-vfs makes downloading & unpacking very simple. The following works well for smaller archives. Once the archive contains thousands of files, it is better to download first and then unpack. (This is due to a performance issue inside VFS2, not groovy-vfs).
@Grapes([
@GrabResolver( name='grysb33r', root='http://dl.bintray.com/ysb33r/grysb33r' ),
@Grab( 'org.ysb33r.groovy:groovy-vfs:0.2' ),
@Grab( 'commons-httpclient:commons-httpclient:3.1')
])
import org.ysb33r.groovy.dsl.vfs.VFS
// This will download the compressed archive from Sourceforge and unpack it to a local directory
new VFS() {