Groovy web console

subscribe to the feed Subscribe
to this
site
ultimate-pipeline-script (via #groovywebconsole)
tweet this snippet Tweet
this
script

ultimate-pipeline-script

Published 3 months ago by David Recuenco with tags jenkins pipeline slaves
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
// jenkins methods and variables
def currentBuild = []

def node(body) {
    body()
}

def stage(name, body) {
    println "Stage: ${name} {"

    body()

    println "} // Stage: ${name}"
    println ""
}

def git(url) {
    println "Cloning ${url}..."
}

def sh(command) {
    println command
}

// util methods

def pipeline(body) {
    println "Pipeline Start {"
    println ""

    try {
        body()
    } catch(def e) {
        currentBuild.result = 'FAILURE'
    }

    println "} // end of pipeline"
}

// slave methods
def withNodejs(version, body) {
    println "Slave: nodejs v${version} {"
    println ""

    body()

    println "} // Slave: nodejs"
    println ""
}

// pipeline
pipeline {
    node {
        stage('Checkout') {
            git 'https://github.com/RecuencoJones/fluent-http'
        }

        withNodejs('7') {
            stage('Install') {
                sh "npm install"
            }

            stage('Build') {
                sh "npm run lint"
                sh "npm run build"
            }

            stage('Test') {
                sh "npm run test:coverage"
                sh "npm run tets:mutations"
            }
        }  
    }
}