Fix Jenkinsfile
This commit is contained in:
36
Jenkinsfile
vendored
36
Jenkinsfile
vendored
@@ -1,27 +1,19 @@
|
||||
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)'){
|
||||
when { expression { fileExists('AMREZ.EOP.sln') } }
|
||||
@@ -37,7 +29,6 @@ pipeline {
|
||||
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 """
|
||||
@@ -51,8 +42,7 @@ pipeline {
|
||||
|
||||
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}
|
||||
@@ -69,10 +59,10 @@ pipeline {
|
||||
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() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user