【k8s】Jenkins实现springcloud应用CI、CD实践
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
sh 'mvn clean package'
}
}
stage('Test') {
steps {
echo 'Testing..'
sh 'mvn test'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
script {
def registry = '127.0.0.1:5000'
def image = '127.0.0.1:5000/sample-microservice-gateway'
def tag = "v${env.BUILD_NUMBER}"
withCredentials([usernamePassword(credentialsId: 'registry-credentials', passwordVariable: 'password', usernameVariable: 'username')]) {
sh "docker login -u ${username} -p ${password} ${registry}"
sh "docker build -t ${image}:${tag} ."
sh "docker push ${image}:${tag}"
}
}
}
}
}
post {
always {
echo 'Finished'
}
}
}
这个Jenkinsfile演示了如何构建、测试Spring Cloud应用程序,并使用Docker进行容器化,然后将其推送到私有仓库。在Deploy阶段,它使用了withCredentials
来安全地处理Docker仓库的登录凭证。最后,在post部分定义了一个always步骤来确保即使构建失败,也总是会执行最后的echo命令。
评论已关闭