Jenkinsfile

Answer

node {
def app
// Project name as per the current/required docker image
env.PROJECT_NAME = 'rfx_nj_pncrfx'
// Git url of the repo
env.GIT_URL = 'http://10.26.61.24/RfxManager/RfxManager/nodejs/RFX_NJ_PnCRfx.git'
// Docker Registry URL
env.DOCKER_REGISTRY = 'http://10.26.61.34:8083'
// ELK URL
env.ELK_URL = "http://10.26.32.145:9200/jenkins-build-status/_doc/"
stage('Clone repository') {
/* Let's make sure we have the repository cloned to our workspace */
deleteDir()
checkout([
$class: 'GitSCM',
branches: [[name: '*/development']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'WipeWorkspace']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'git-credentials-eam', url: "${env.GIT_URL}"]]])
}
stage('Check latest git tag') {
/* Let's get the latest tag */
git_ver = sh(returnStdout: true, script: 'git describe --abbrev=0 --tags').trim()
env.TAG = git_ver
}
// stage('Check environment') {
// /* Let's make sure we have the repository cloned to our workspace */
// sh 'printenv'
// }
stage('Build image') {
/* This builds the actual image; synonymous to
* docker build on the command line */
app = docker.build("${env.PROJECT_NAME}")
}
stage('Audit') {
/* fix npm audit issues*/
app.inside {
sh 'echo "Audit"'
sh 'npm audit fix'
}
}
stage('Push image') {
/* Finally, we'll push the image with two tags:
* First, the incremental build number from Jenkins
* Second, the 'latest' tag.
* Pushing multiple tags is cheap, as all the layers are reused. */
docker.withRegistry("${env.DOCKER_REGISTRY}", 'dockerregistry') {
// app.push("${env.BUILD_NUMBER}")
app.push("${env.TAG}")
}
}
stage('Create deployment yml') {
/* create environment aware deployment files. */
sh 'cp k8s/deployment.yml k8s/deployment-dev.yml'
sh 'cp k8s/deployment.yml k8s/deployment-staging.yml'
sh 'cp k8s/deployment.yml k8s/deployment-prod.yml'
sh 'cp k8s/deployment.yml k8s/deployment-hotfix.yml'
}
stage('Deploy to K8s Dev') {
/* Deploy to k8s dev
* Set the environment as dev */
env.NODE_ENV = 'dev'
sh "sed -i 's/<NODE_ENV>/${env.NODE_ENV}/g' k8s/deployment-dev.yml"
sh "sed -i 's/<TAG>/${env.TAG}/g' k8s/deployment-dev.yml"
sshagent (credentials: ['deployk8sdev']) {
sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no riladmin@10.26.24.15 mkdir -p /tmp/deployk8s/'${env.PROJECT_NAME}'"
sh "scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no k8s/deployment-dev.yml riladmin@10.26.24.15:/tmp/deployk8s/'${env.PROJECT_NAME}'"
sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no riladmin@10.26.24.15 sudo kubectl apply -f /tmp/deployk8s/'${env.PROJECT_NAME}'/deployment-dev.yml"
}
}
stage ('Update ELK') {
def ts = new Date().getTime()
def data = "{"buildNo":${env.BUILD_NUMBER},"data":{},"name":"${env.PROJECT_NAME}","status":"success","ts":"${ts}"}"
sh "curl -H 'Content-Type: application/json' -XPOST ${env.ELK_URL} -d '${data}'"
}
stage ('Archive') {
archiveArtifacts allowEmptyArchive: true,
artifacts: '**',
caseSensitive: false,
excludes: 'node_modules/**/*, logs/**',
onlyIfSuccessful: true
}
}

All 2d Questions

Ask your interview questions on 2d

Write Your comment or Questions if you want the answers on 2d from 2d Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---