Files
demo-app/Jenkinsfile

50 lines
1.5 KiB
Groovy
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pipeline {
agent { label 'docker' }
// SCM 轮询:每分钟检查一次 Gitea 是否有新提交(不依赖 webhook / CSRF)
triggers { pollSCM('H/1 * * * *') }
environment {
HARBOR = '192.168.8.11:30002'
PROJECT = 'person-photo'
IMAGE_NAME = 'demo-app'
IMAGE_TAG = "${env.BUILD_NUMBER}"
}
stages {
stage('拉取代码') {
steps { checkout scm }
}
stage('构建镜像') {
steps {
container('docker') {
sh '''
for i in $(seq 1 30); do
if docker info >/dev/null 2>&1; then echo "dockerd ready (~$((i*2))s)"; break; fi
sleep 2
done
docker info >/dev/null 2>&1 || { echo "dockerd not ready, abort"; exit 1; }
docker build -t $HARBOR/$PROJECT/$IMAGE_NAME:$IMAGE_TAG .
docker tag $HARBOR/$PROJECT/$IMAGE_NAME:$IMAGE_TAG $HARBOR/$PROJECT/$IMAGE_NAME:latest
'''
}
}
}
stage('推送镜像') {
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId: 'harbor-cred',
usernameVariable: 'HARBOR_USER',
passwordVariable: 'HARBOR_PASS')]) {
sh '''
echo "$HARBOR_PASS" | docker login $HARBOR -u "$HARBOR_USER" --password-stdin
docker push $HARBOR/$PROJECT/$IMAGE_NAME:$IMAGE_TAG
docker push $HARBOR/$PROJECT/$IMAGE_NAME:latest
'''
}
}
}
}
}
}