Jenkins Job DSL

I’ve wanted to post for some time a couple of thoughts and templates for good DSL job scripts for Jenkins(Hudson) but haven’t been able to pull enough details together to make it cohesive. Nothing’s changed in that regard but I’m fed up with looking at the draft…

Assuming you have all the pre-reqs for running DSL scripts (possibly a boot strap job [check this example job] as well) you’re biggest hurdle is going to be making sense of the DSL script. Below is a basic example that includes some of the preliminary needs for my application of this.

def gitBaseUrl = 'git@github.com/Scriobhaim/'
def shortCode = 'ACME'
def phpGitName = shortCode.toLowerCase() + '-appstatic'
def groupID = 'im.scriobha'

//------------ View --------------------------------------------------------------------------------------------------//
listView(shortCode){
    description('All jobs for ACME')
    filterBuildQueue(false)
    filterExecutors(false)
    jobs {
        name(shortCode)
        regex(shortCode + '_.+')
    }
    columns {
        status()
        weather()
        name()
        lastSuccess()
        lastFailure()
        lastDuration()
        buildButton()
    }
}

//------------ [NAME] Jobs -------------------------------------------------------------------------------------------//

mavenJob (shortCode + '_DEV_AppStatic'){
    logRotator(daysToKeepInt = -1, numToKeepInt = 5, artifactDaysToKeepInt = 30, artifactNumToKeepInt = -1)
    concurrentBuild(allowConcurrentBuild = true)
    quietPeriod(600)
    triggers {
        githubPush()
    }
    scm {
        git{
            remote{
                url("git@github.com:Synegen/${phpGitName}.git")
            }
            branches('*/master')
            configure { git ->
                git / 'extensions' / 'hudson.plugins.git.extensions.impl.SparseCheckoutPaths' / 'sparseCheckoutPaths' {
                    'hudson.plugins.git.extensions.impl.SparseCheckoutPath' {
                        path("AppSubStatic")
                    }
                }
            }
        }
    }
    rootPOM('PHPSubStatic/pom.xml')
    goals('clean package -Dmaven.test.failure.ignore=false')
    postBuildSteps('UNSTABLE'){
        shell('# Fail on first error: \n' +
            'set -e\n' +
            '\n' +
            'scp target/phpstatic-*.zip '+ shortCode.toLowerCase() + '-dev-app1:/tmp/.\n' +
            'ssh '+ shortCode.toLowerCase() + '-dev-app1 \'sudo unzip -d /mnt/app-www/ -o /tmp/drupal-*.zip\'\n' +
            'ssh '+ shortCode.toLowerCase() + '-dev-app1 \'sudo chown -R www-data:www-data /mnt/app-www\'\n' +
            'ssh '+ shortCode.toLowerCase() + '-dev-app1 \'sudo rm /tmp/phpstatic-*.zip\'')
    }
    publishers {
        mailer('developers@acme.com', false, true)
    }
}