Last active
July 26, 2024 19:47
-
-
Save eeganlf/7e575c119ff20e56d2c25fa567790825 to your computer and use it in GitHub Desktop.
Jenkinsfile LFS261 Lab 8 final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent none | |
stages { | |
stage('worker-build') { | |
agent { | |
docker { | |
image 'maven:3.9.8-sapmachine-21' | |
args '-v $HOME/.m2:/root/.m2' | |
} | |
} | |
when { | |
changeset '**/worker/**' | |
} | |
steps { | |
echo 'Compiling worker app..' | |
dir(path: 'worker') { | |
sh 'mvn compile' | |
} | |
} | |
} | |
stage('worker test') { | |
agent { | |
docker { | |
image 'maven:3.9.8-sapmachine-21' | |
args '-v $HOME/.m2:/root/.m2' | |
} | |
} | |
when { | |
changeset '**/worker/**' | |
} | |
steps { | |
echo 'Running Unit Tets on worker app.' | |
dir(path: 'worker') { | |
sh 'mvn clean test' | |
} | |
} | |
} | |
stage('worker-package') { | |
agent { | |
docker { | |
image 'maven:3.9.8-sapmachine-21' | |
args '-v $HOME/.m2:/root/.m2' | |
} | |
} | |
when { | |
branch 'master' | |
changeset '**/worker/**' | |
} | |
steps { | |
echo 'Packaging worker app' | |
dir(path: 'worker') { | |
sh 'mvn package -DskipTests' | |
archiveArtifacts(artifacts: '**/target/*.jar', fingerprint: true) | |
} | |
} | |
} | |
stage('worker-docker-package') { | |
agent any | |
when { | |
changeset '**/worker/**' | |
branch 'master' | |
} | |
steps { | |
echo 'Packaging worker app with docker' | |
script { | |
docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { | |
def workerImage = docker.build("xxxxx/worker:v${env.BUILD_ID}", './worker') | |
workerImage.push() | |
workerImage.push("${env.BRANCH_NAME}") | |
workerImage.push('latest') | |
} | |
} | |
} | |
} | |
stage('result-build') { | |
agent { | |
docker { | |
image 'node:22.4.0-alpine' | |
} | |
} | |
when { | |
changeset '**/result/**' | |
} | |
steps { | |
echo 'Compiling result app..' | |
dir(path: 'result') { | |
sh 'npm install' | |
} | |
} | |
} | |
stage('result-test') { | |
agent { | |
docker { | |
image 'node:22.4.0-alpine' | |
} | |
} | |
when { | |
changeset '**/result/**' | |
} | |
steps { | |
echo 'Running Unit Tests on result app..' | |
dir(path: 'result') { | |
sh 'npm install' | |
sh 'npm test' | |
} | |
} | |
} | |
stage('result-docker-package') { | |
agent any | |
when { | |
changeset '**/result/**' | |
branch 'master' | |
} | |
steps { | |
echo 'Packaging result app with docker' | |
script { | |
docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { | |
def resultImage = docker.build("xxxxx/result:v${env.BUILD_ID}", './result') | |
resultImage.push() | |
resultImage.push("${env.BRANCH_NAME}") | |
resultImage.push('latest') | |
} | |
} | |
} | |
} | |
stage('vote-build') { | |
agent { | |
docker { | |
image 'python:2.7.16-slim' | |
args '--user root' | |
} | |
} | |
when { | |
changeset '**/vote/**' | |
} | |
steps { | |
echo 'Compiling vote app.' | |
dir(path: 'vote') { | |
sh 'pip install -r requirements.txt' | |
} | |
} | |
} | |
stage('vote-test') { | |
agent { | |
docker { | |
image 'python:2.7.16-slim' | |
args '--user root' | |
} | |
} | |
when { | |
changeset '**/vote/**' | |
} | |
steps { | |
echo 'Running Unit Tests on vote app.' | |
dir(path: 'vote') { | |
sh 'pip install -r requirements.txt' | |
sh 'nosetests -v' | |
} | |
} | |
} | |
stage('vote integration'){ | |
agent any | |
when{ | |
changeset "**/vote/**" | |
branch 'master' | |
} | |
steps{ | |
echo 'Running Integration Tests on vote app' | |
dir('vote'){ | |
sh 'sh integration_test.sh' | |
} | |
} | |
} | |
stage('vote-docker-package') { | |
agent any | |
steps { | |
echo 'Packaging vote app with docker' | |
script { | |
docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { | |
// ./vote is the path to the Dockerfile that Jenkins will find from the Github repo | |
def voteImage = docker.build("xxxxx/vote:${env.GIT_COMMIT}", "./vote") | |
voteImage.push() | |
voteImage.push("${env.BRANCH_NAME}") | |
voteImage.push("latest") | |
} | |
} | |
} | |
} | |
stage('deploy to dev') { | |
agent any | |
when { | |
branch 'master' | |
} | |
steps { | |
echo 'Deploy instavote app with docker compose' | |
sh 'docker-compose up -d' | |
} | |
} | |
} | |
post { | |
always { | |
echo 'Building mono pipeline for voting app is completed.' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment