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

Jenkins Pipeline for Sparktodo Build

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)
111 views2 pages

Jenkins Pipeline for Sparktodo Build

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

#!

groovy

def releasedVersion

node('master') {
def dockerTool = tool name: 'docker', type:
'[Link]'
withEnv(["DOCKER=${dockerTool}/bin"]) {
stage('Prepare') {
deleteDir()
parallel Checkout: {
checkout scm
}, 'Run Zalenium': {
dockerCmd '''run -d --name zalenium -p 4444:4444 \
-v /var/run/[Link]:/var/run/[Link] \
--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 -[Link]=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 [Link] test@[Link] && git config
[Link] 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('[Link]') =~ '<version>(.+)-SNAPSHOT</version>')[0][1]
}

[Link]
[Link]
pipeline
[Link]

You might also like