pipeline { agent any parameters { booleanParam(name: 'DeployAll', defaultValue: false, description: 'Deploy Site/WS ?') booleanParam(name: 'deploySite', defaultValue: false, description: 'Deploy Site ?') } triggers { pollSCM('* * * * *') } environment { now = new Date().format('yyyyMMdd-HHmm', TimeZone.getTimeZone('UTC')) DOCKER_HOST = 'tcp://192.168.2.20:2375' IMAGE_TAG = 'latest' DOCKER_IMAGE = 'Geradoresfe:lastest' DOCKER_TAG = "${env.BUILD_ID}" DOCKER_REGISTRY = 'Shini89' //'your-docker-registry.com' // Registro Docker REACT_DIR = 'geradoresfe' SERVICE_DIR = 'GeradoresService' API_DIR = 'geradoresws' } stages { stage('Validate Docker Connection') { steps { script { echo "Validando conexão com Docker remoto: ${DOCKER_HOST}" // Testa a conexão com o Docker remoto sh 'docker info' } } } stage('Check for Changes') { steps { script { CodeChanges = currentBuild.changeSets != [] if (CodeChanges) { def changeLogSets = currentBuild.changeSets for (int i = 0; i < changeLogSets.size(); i++) { def entries = changeLogSets[i].items for (int j = 0; j < entries.length; j++) { def entry = entries[j] message = message + "
Autor: ${entry.author.fullName} ( ${entry.author} )
Commit: ${entry.msg}" def files = new ArrayList(entry.affectedFiles) message = message + '
Ficheiros:
' } } } } } } stage('Checkout Code') { steps { git branch: 'master', url: 'https://git.homeware.pt/Marco/Geradores.git' } } /******************************************************* Stage BUILD *******************************************************/ stage('Build DLL') { steps { dir("${env.SERVICE_DIR}") { sh 'dotnet build -c Release' } } } stage('Build WS') { steps { dir("${env.API_DIR}") { sh 'dotnet build -c Release' } } } stage('Build WS Docker Image') { steps { dir("${env.API_DIR}") { // Construir a imagem Docker do Backend usando o Dockerfile existente script { docker.build("${env.API_DIR}:${IMAGE_TAG}", '.') } } } } stage('Build React') { steps { dir("${env.REACT_DIR}") { sh 'npm install' sh 'npm run build' /* sh """ docker build -t ${env.DOCKER_REGISTRY}/react-frontend:latest . docker push ${env.DOCKER_REGISTRY}/react-frontend:latest """*/ } } } stage('Build React Docker Image') { steps { dir("${env.REACT_DIR}") { script { docker.build("${env.REACT_DIR}:${IMAGE_TAG}", '.') } } } } stage('Push Docker Images') { steps { script { // Fazer login no Docker Hub (ou outro registro Docker) sh 'docker login -u Shini89 -p Spongebob!1' // Publicar as imagens sh "docker push ${env.API_DIR}:${IMAGE_TAG}" sh "docker push ${env.REACT_DIR}:${IMAGE_TAG}" } } } } post { success { echo 'Services deployed successfully!' sh 'docker system prune -f' } failure { echo 'Failed to deploy services. Check logs.' } } }