0% found this document useful (0 votes)
95 views2 pages

Jenkinspipeline Build Tools

This Jenkins pipeline builds and tests a Spark todo application, then releases and deploys the application. It uses Docker for building, testing and deployment. The pipeline checks out code, builds a Docker image, runs unit and integration tests inside Docker containers, releases a new version, tags the image and deploys it to production.

Uploaded by

Sriharshi Yarra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views2 pages

Jenkinspipeline Build Tools

This Jenkins pipeline builds and tests a Spark todo application, then releases and deploys the application. It uses Docker for building, testing and deployment. The pipeline checks out code, builds a Docker image, runs unit and integration tests inside Docker containers, releases a new version, tags the image and deploys it to production.

Uploaded by

Sriharshi Yarra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#!

groovy

def releasedVersion

node('master') {
def dockerTool = tool name: 'docker', type:
'org.jenkinsci.plugins.docker.commons.tools.DockerTool'
withEnv(["DOCKER=${dockerTool}/bin"]) {
stage('Prepare') {
deleteDir()
parallel Checkout: {
checkout scm
}, 'Run Zalenium': {
dockerCmd '''run -d --name zalenium -p 4444:4444 \
-v /var/run/docker.sock:/var/run/docker.sock \
--network="host" \
--privileged dosel/zalenium:3.4.0a start --videoRecordingEnabled false
--chromeContainers 1 --firefoxContainers 0'''
}
}

stage('Build') {
withMaven(maven: 'Maven 3') {
dir('app') {
sh 'mvn clean package'
dockerCmd 'build --tag automatingguy/sparktodo:SNAPSHOT .'
}
}
}

stage('Deploy') {
stage('Deploy') {
dir('app') {
dockerCmd 'run -d -p 9999:9999 --name "snapshot" --network="host"
automatingguy/sparktodo:SNAPSHOT'
}
}
}

stage('Tests') {
try {
dir('tests/rest-assured') {
sh './gradlew clean test'
}
} finally {
junit testResults: 'tests/rest-assured/build/*.xml', allowEmptyResults:
true
archiveArtifacts 'tests/rest-assured/build/**'
}

dockerCmd 'rm -f snapshot'


dockerCmd 'run -d -p 9999:9999 --name "snapshot" --network="host"
automatingguy/sparktodo:SNAPSHOT'

try {
withMaven(maven: 'Maven 3') {
dir('tests/bobcat') {
sh 'mvn clean test -Dmaven.test.failure.ignore=true'
}
}
} finally {
junit testResults: 'tests/bobcat/target/*.xml', allowEmptyResults: true
archiveArtifacts 'tests/bobcat/target/**'
}

dockerCmd 'rm -f snapshot'


dockerCmd 'stop zalenium'
dockerCmd 'rm zalenium'
}

stage('Release') {
withMaven(maven: 'Maven 3') {
dir('app') {
releasedVersion = getReleasedVersion()
withCredentials([usernamePassword(credentialsId: 'github',
passwordVariable: 'password', usernameVariable: 'username')]) {
sh "git config user.email test@automatingguy.com && git config
user.name Jenkins"
sh "mvn release:prepare release:perform -Dusername=${username}
-Dpassword=${password}"
}
dockerCmd "build --tag automatingguy/sparktodo:$
{releasedVersion} ."
}
}
}

stage('Deploy @ Prod') {
dockerCmd "run -d -p 9999:9999 --name 'production' automatingguy/sparktodo:
${releasedVersion}"
}
}
}

def dockerCmd(args) {
sh "sudo ${DOCKER}/docker ${args}"
}

def getReleasedVersion() {
return (readFile('pom.xml') =~ '<version>(.+)-SNAPSHOT</version>')[0][1]
}

https://bulldogjob.com/readme/exploring-jenkins-pipelines-a-simple-delivery-flow
https://stackoverflow.com/questions/60263150/using-withenv-in-a-declarative-
pipeline
https://automatingguy.com/2017/11/06/jenkins-pipelines-simple-delivery-flow/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy