ci/integrate.groovy
author Jan Vrany <jan.vrany@labware.com>
Tue, 23 Jun 2020 12:21:39 +0100
changeset 295 a04034567c92
parent 292 00d3840350c2
permissions -rw-r--r--
CI: cleanup workspace after successfull build ...to save disk space.

/*
 * Run default pipeline. See `steps.groovy` for details.
 */

def steps;

/*
 * A helper function to return a branch to build.
 *
 * For normal jobs this is the value of 'Branch' field from SCM configuration.
 * For multibranch jobs, this is the value of BRANCH_NAME environment variable.
 *
 * This is the same as build() function in `steps.groovy` and should be kept
 * in sync. We cannot use the one there as we yet have to load it.
 */
def branch() {
    if (env.BRANCH_NAME == null) {
        return scm.getBranch();
    } else {
        return env.BRANCH_NAME;
    }
}

stage ( "Load Pipeline") {
    node {
        /*
         * Do not use default workspace here as checkout
         * would erase all contents. Use a dedicated
         * workspace instead
         */
        ws ("workspace/${env.JOB_NAME}@loadpipeline") {
            sshagent([ scm.getCredentialsId() ]) {
                sh  """
                    if [ -f ci/steps.groovy ]; then
                        hg pull --ssh ssh ${scm.getSource()}
                    else
                        hg clone --ssh ssh ${scm.getSource()} .
                    fi
                    hg up ${branch()}
                    """
            }
            steps = load "ci/steps.groovy"
        }
    }
}

/*
 * Set the branch to build to make sure it's in sync...
 */
steps.branch = branch()

/*
 * ...and fire the pipeline
 */
steps.integration()
steps.cleanup()