61 lines
1.6 KiB
Groovy
61 lines
1.6 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
HARBOR = '43.134.235.58:58080'
|
|
IMAGE = "${HARBOR}/buildflow/buildflow-portal"
|
|
TAG = "${env.BUILD_NUMBER}"
|
|
}
|
|
|
|
options {
|
|
timeout(time: 30, unit: 'MINUTES')
|
|
buildDiscarder(logRotator(numToKeepStr: '10'))
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
checkout scm
|
|
sh 'git log --oneline -5'
|
|
}
|
|
}
|
|
|
|
stage('Build Image') {
|
|
steps {
|
|
sh """
|
|
docker build -t ${IMAGE}:${TAG} .
|
|
docker tag ${IMAGE}:${TAG} ${IMAGE}:latest
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('Push Harbor') {
|
|
steps {
|
|
withCredentials([usernamePassword(credentialsId: 'harbor-credentials', usernameVariable: 'HARBOR_USER', passwordVariable: 'HARBOR_PASS')]) {
|
|
sh """
|
|
echo "\$HARBOR_PASS" | docker login -u "\$HARBOR_USER" --password-stdin ${HARBOR}
|
|
docker push ${IMAGE}:${TAG}
|
|
docker push ${IMAGE}:latest
|
|
docker logout ${HARBOR}
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Deploy') {
|
|
steps {
|
|
echo 'Deploy 待 Agent 就绪后启用'
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success { echo '=== build-flow.portal CI/CD SUCCESS ===' }
|
|
failure { echo '=== build-flow.portal CI/CD FAILED ===' }
|
|
always {
|
|
sh "docker rmi ${IMAGE}:${TAG} ${IMAGE}:latest || true"
|
|
deleteDir()
|
|
}
|
|
}
|
|
}
|