104 lines
2.9 KiB
Groovy
104 lines
2.9 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
DOCKER_REGISTRY = 'git.homeware.pt'
|
|
DOCKER_TAG = "${env.BUILD_ID}"
|
|
|
|
REACT_DIR = 'geradoresfe'
|
|
SERVICE_DIR = 'GeradoresService'
|
|
API_DIR = 'GeradoresWS'
|
|
|
|
REACT_IMAGE = "${DOCKER_REGISTRY}/geradores/fe:${DOCKER_TAG}"
|
|
WS_IMAGE = "${DOCKER_REGISTRY}/geradores/ws:${DOCKER_TAG}"
|
|
|
|
DOCKER_CREDENTIALS_ID = 'docker-registry-creds'
|
|
KUBECONFIG_CREDENTIALS_ID = 'kubeconfig-jenkins'
|
|
GIT_CREDENTIALS_ID = '3e806a5c-ee46-49fb-974d-15f3fe2e1d49'
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Preparar Ambiente') {
|
|
steps {
|
|
script {
|
|
echo "Verificar Docker local"
|
|
sh 'docker version'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Checkout Repositório') {
|
|
steps {
|
|
git branch: 'master',
|
|
url: 'https://git.homeware.pt/Marco/Geradores.git',
|
|
credentialsId: env.GIT_CREDENTIALS_ID
|
|
}
|
|
}
|
|
|
|
stage('Build .NET Services') {
|
|
steps {
|
|
dir("${SERVICE_DIR}") {
|
|
sh 'dotnet build -c Release'
|
|
}
|
|
dir("${API_DIR}") {
|
|
sh 'dotnet build -c Release'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Build React App') {
|
|
steps {
|
|
dir("${REACT_DIR}") {
|
|
sh 'npm install'
|
|
sh 'npm run build'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Docker Build Imagens') {
|
|
steps {
|
|
script {
|
|
docker.build("${WS_IMAGE}")
|
|
docker.build("${REACT_IMAGE}", "${REACT_DIR}")
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Push para Docker Registry') {
|
|
steps {
|
|
script {
|
|
docker.withRegistry("https://${DOCKER_REGISTRY}", DOCKER_CREDENTIALS_ID) {
|
|
docker.image("${WS_IMAGE}").push()
|
|
docker.image("${REACT_IMAGE}").push()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Deploy no Kubernetes') {
|
|
steps {
|
|
withKubeConfig(credentialsId: KUBECONFIG_CREDENTIALS_ID) {
|
|
script {
|
|
// Substitui as imagens no manifest e aplica
|
|
sh """
|
|
sed 's|{{WS_IMAGE}}|${WS_IMAGE}|g; s|{{FE_IMAGE}}|${REACT_IMAGE}|g' k8s/deployment.template.yaml > k8s/deployment.yaml
|
|
kubectl apply -f k8s/deployment.yaml
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
echo 'Deploy feito com sucesso!'
|
|
sh 'docker system prune -f'
|
|
}
|
|
failure {
|
|
echo 'Erro no pipeline. Verifica os logs!'
|
|
}
|
|
}
|
|
}
|