Move to new server
This commit is contained in:
63
Jenkinsfile
vendored
Normal file
63
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
// This Jenkinsfile defines a declarative pipeline
|
||||
pipeline {
|
||||
|
||||
options {
|
||||
disableConcurrentBuilds()
|
||||
}
|
||||
agent any
|
||||
|
||||
/*
|
||||
agent {
|
||||
docker {
|
||||
image 'maven:3.9.3-eclipse-temurin-21'
|
||||
args '-v $HOME/.m2:/root/.m2'
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Defines the sequence of stages that will be executed
|
||||
stages {
|
||||
// This stage checks out the source code from the SCM (Source Code Management) system
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
// This command checks out the source code from the SCM into the Jenkins workspace
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'mvn -B clean package'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Docker Build') {
|
||||
steps {
|
||||
sh 'docker build -t upquark/swiss-backend:latest -t upquark/swiss-backend:${BUILD_NUMBER} .'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Push the Docker Image to DockerHUb') {
|
||||
steps {
|
||||
script {
|
||||
withCredentials([string(credentialsId: 'c7783e4f-2f79-482f-885f-dfb39f8c02d3', variable: 'docker_hub')]) {
|
||||
sh 'docker login -u upquark -p ${docker_hub}'
|
||||
}
|
||||
sh 'docker push upquark/swiss-backend:latest'
|
||||
sh 'docker push upquark/swiss-backend:${BUILD_NUMBER}'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy to Kubernetes') {
|
||||
steps {
|
||||
script {
|
||||
kubeconfig(credentialsId: 'k3s-kubeconfig') {
|
||||
sh 'cat k8s/deployment.yaml | sed "s/latest/$BUILD_NUMBER/g" | kubectl apply -n swiss -f -'
|
||||
sh 'kubectl apply -f k8s/service.yaml -n swiss'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user