I am new to Jenkins. I am doing a build through Jenkins, but the build is very slow. Is there any way I can speed it up?
#!/usr/bin/env groovy
@Library('cplib') _
import com.sports.paas.cplib.helpers.Build
import com.sports.paas.cplib.helpers.Workspace
import com.sports.paas.cplib.utils.Openshift
def bld = new Build()
def wspace = new Workspace()
def osh = new Openshift()
def appReleaseTag = ""
def NODE_HOME = "${JENKINS_HOME_SLAVE}/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node_6.11.1"
def projectName = "player"
def appName = "ball"
def appOcpConfigBranch = "master"
// ########################################################################################
// PIPELINE WORKFLOW
// ########################################################################################
pipeline {
agent { node('nodejs')}
tools {
nodejs 'nodejs-8.11.2'
}
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '30', daysToKeepStr: '15'))
skipDefaultCheckout(true)
timestamps()
skipStagesAfterUnstable()
}
parameters {
choice (
name : 'DEPLOY_ENVIRONMENT',
choices: ' \nunit\ntest\nstage',
description: '[Required] Select the location to deploy.'
)
}
stages {
stage('Prepare') {
steps {
script {
log.info "Explicit scm checkout ..."
checkout scm
wspace.init()
// wspace.checkoutAppOcpConfig(appName, appOcpConfigBranch)
appReleaseTag = wspace.getBuildProperty("version") + "." + env.BUILD_NUMBER
}
}
}
stage('Build Artifacts') {
steps {
script {
sh """
echo "Building artifacts ..."
export PATH=$PATH:$NODE_HOME/bin;
echo "Running node build ..."
# Please build your application using npm or yarn. Application build
# using yarn has been tested for a 35% faster execution when compared to yarn.
#npm install --no-optional --production --silent
npm install
echo "@@@ NPM RUN PROD ( BUILD )"
npm run build
#yarn
"""
}
prepareForBuildImage()
}
}
stage('Build Image') {
steps {
script {
if(!wspace.releaseVersionExists()) {
appReleaseTag = osh.buildAppImage(appName, appReleaseTag)
} else {
appReleaseTag = env.RELEASE_VERSION
}
}
}
}
stage('Deploy Unit') {
steps {
script {
envName=env.DEPLOY_ENVIRONMENT
osh.deploy(projectName+"-"+envName, appName, envName,appReleaseTag)
}
}
}
} //stages
} // pipeline
def prepareForBuildImage() {
sh '''
echo "Preparing Image contents ..."
rm -rf tmp
mkdir -p tmp
chmod -R 777 tmp
echo "Compressing files ..."
tar cvzf tmp.tar.gz client server *.json node_modules index.js build.properties README.md
cp -pr tmp.tar.gz tmp/
echo "Decompressing files ..."
cd tmp
tar xvzf tmp.tar.gz
rm -fr tmp.tar.gz
cd ..
echo "Displaying deployment artifacts ..."
ls -Rlt tmp/ --ignore=node_modules
'''
}