diff --git a/Jenkinsfile b/Jenkinsfile index 2c654ed..ffea505 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,29 +1,21 @@ pipeline { agent any + options { ansiColor('xterm'); timestamps(); disableConcurrentBuilds(); timeout(time:25, unit:'MINUTES') } - options { - ansiColor('xterm'); timestamps(); disableConcurrentBuilds() - timeout(time: 25, unit: 'MINUTES') - } - - /* ให้ Gitea ยิง webhook แล้ว build ได้เลย */ - triggers { - giteaPush() - } + // ถ้าอยากมี fallback ให้ Jenkinsเช็คทุก 2 นาที ให้เพิ่มบรรทัดด้านล่างแทน giteaPush(): + // triggers { pollSCM('H/2 * * * *') } environment { REGISTRY = 'registry.aetherframe.tech' - IMAGE = 'simulationable/eop-services-api' // แนะนำเป็นตัวพิมพ์เล็กทั้งหมด - APP_PORT = '8080' // Kestrel ใน container ฟัง 8080 - HOST_PORT = '5002' // พอร์ตฝั่ง host ที่ Nginx จะ proxy เข้า + IMAGE = 'simulationable/eop-services-api' + APP_PORT = '8080' + HOST_PORT = '5002' } stages { - stage('Checkout') { - steps { checkout scm } - } + stage('Checkout'){ steps { checkout scm } } - stage('Unit Tests (optional)') { + stage('Unit Tests (optional)'){ when { expression { fileExists('AMREZ.EOP.sln') } } steps { sh ''' @@ -33,11 +25,10 @@ pipeline { } } - stage('Docker Build') { + stage('Docker Build'){ steps { sh 'docker version' script { - /* รองรับทั้ง Multibranch (BRANCH_NAME) และ Pipeline เดี่ยว (GIT_BRANCH) */ def branch = (env.BRANCH_NAME ?: env.GIT_BRANCH ?: 'main').replaceFirst(/^origin\\//,'') def tag = "${branch}-${env.BUILD_NUMBER}" sh """ @@ -49,10 +40,9 @@ pipeline { } } - stage('Docker Push') { + stage('Docker Push'){ steps { - withCredentials([usernamePassword(credentialsId: 'registry-basic', - usernameVariable: 'REG_USER', passwordVariable: 'REG_PASS')]) { + withCredentials([usernamePassword(credentialsId:'registry-basic', usernameVariable:'REG_USER', passwordVariable:'REG_PASS')]){ sh """ echo "\$REG_PASS" | docker login ${REGISTRY} -u "\$REG_USER" --password-stdin docker push ${REGISTRY}/${IMAGE}:${IMAGE_TAG} @@ -63,16 +53,16 @@ pipeline { } } - stage('Deploy (same host)') { + stage('Deploy (same host)'){ when { branch 'main' } steps { sh """ set -eux docker rm -f eop-services-api || true - docker run -d --name eop-services-api \\ - -p 127.0.0.1:${HOST_PORT}:${APP_PORT} \\ - -e ASPNETCORE_URLS=http://+:${APP_PORT} \\ - --restart=always \\ + docker run -d --name eop-services-api \ + -p 127.0.0.1:${HOST_PORT}:${APP_PORT} \ + -e ASPNETCORE_URLS=http://+:${APP_PORT} \ + --restart=always \ ${REGISTRY}/${IMAGE}:latest """ } @@ -80,7 +70,7 @@ pipeline { } post { - success { echo "Deployed at http://127.0.0.1:${HOST_PORT} (จะเข้าผ่าน https หลังตั้ง Nginx)" } + success { echo "Deployed at http://127.0.0.1:${HOST_PORT} (ผ่าน Nginx/SSL เมื่อเซ็ต)" } always { cleanWs() } } }