agent-foundation/Jenkinsfile

126 lines
3.4 KiB
Plaintext
Raw Normal View History

2026-06-01 19:31:08 +08:00
pipeline {
agent any
2026-09-23 10:49:35 +08:00
options {
timestamps()
disableConcurrentBuilds()
timeout(time: 45, unit: 'MINUTES')
}
2026-06-01 19:31:08 +08:00
environment {
APP_NAME = 'agent-foundation'
2026-09-23 10:49:35 +08:00
IMAGE_NAME = 'agent-foundation'
2026-06-01 19:31:08 +08:00
IMAGE_TAG = "${env.BUILD_NUMBER}"
CONTAINER_NAME = 'agent-foundation'
2026-09-23 10:49:35 +08:00
APP_PORT = '8880'
CONTAINER_PORT = '8880'
MAVEN_IMAGE = 'maven:3.9.16-eclipse-temurin-17-alpine'
RUNTIME_IMAGE = 'eclipse-temurin:17-jre-alpine'
DOCKER_BUILDKIT = '1'
2026-06-01 19:31:08 +08:00
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
2026-09-23 10:49:35 +08:00
stage('Pull Base Images') {
steps {
script {
[env.MAVEN_IMAGE, env.RUNTIME_IMAGE].each { image ->
retry(3) {
timeout(time: 10, unit: 'MINUTES') {
sh "docker pull ${image}"
}
}
}
}
}
}
2026-06-01 19:31:08 +08:00
stage('Build Image') {
steps {
script {
2026-09-23 10:49:35 +08:00
timeout(time: 20, unit: 'MINUTES') {
sh """
docker build --progress=plain \
--build-arg MAVEN_IMAGE=${MAVEN_IMAGE} \
--build-arg RUNTIME_IMAGE=${RUNTIME_IMAGE} \
-t ${IMAGE_NAME}:${IMAGE_TAG} \
-t ${IMAGE_NAME}:latest .
"""
}
2026-06-01 19:31:08 +08:00
}
}
}
stage('Push Image') {
when {
expression { return env.IMAGE_NAME?.contains('/') }
}
steps {
withCredentials([usernamePassword(credentialsId: 'docker-registry-cred', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh 'echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin'
sh "docker push ${IMAGE_NAME}:${IMAGE_TAG}"
sh "docker push ${IMAGE_NAME}:latest"
}
}
}
stage('Deploy') {
steps {
withCredentials([
string(credentialsId: 'deepseek-api-key', variable: 'DEEPSEEK_API_KEY'),
string(credentialsId: 'wecom-corp-id', variable: 'WECOM_CORP_ID'),
string(credentialsId: 'wecom-agent-id', variable: 'WECOM_AGENT_ID'),
string(credentialsId: 'wecom-secret', variable: 'WECOM_SECRET'),
string(credentialsId: 'wecom-token', variable: 'WECOM_TOKEN')
]) {
sh "docker rm -f ${CONTAINER_NAME} || true"
sh '''
docker run -d \
--name ${CONTAINER_NAME} \
2026-09-23 10:49:35 +08:00
--restart unless-stopped \
-p ${APP_PORT}:${CONTAINER_PORT} \
2026-06-01 19:31:08 +08:00
-e DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY} \
-e WECOM_CORP_ID=${WECOM_CORP_ID} \
-e WECOM_AGENT_ID=${WECOM_AGENT_ID} \
-e WECOM_SECRET=${WECOM_SECRET} \
-e WECOM_TOKEN=${WECOM_TOKEN} \
${IMAGE_NAME}:${IMAGE_TAG}
'''
}
}
}
2026-09-23 10:49:35 +08:00
stage('Verify') {
steps {
timeout(time: 3, unit: 'MINUTES') {
sh '''
for attempt in $(seq 1 30); do
if docker exec ${CONTAINER_NAME} wget -qO- http://127.0.0.1:${CONTAINER_PORT}/actuator/health | grep -q '"status":"UP"'; then
echo "Health check passed"
exit 0
fi
sleep 5
done
docker logs --tail 200 ${CONTAINER_NAME}
exit 1
'''
}
}
}
2026-06-01 19:31:08 +08:00
}
post {
success {
echo "Deploy success: ${IMAGE_NAME}:${IMAGE_TAG}"
}
failure {
echo 'Pipeline failed'
}
}
}