1 Star 0 Fork 7

生不出人,我很抱歉/devops-maven-sample

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Jenkinsfile 4.09 KB
一键复制 编辑 原始数据 按行查看 历史
梁军杰 提交于 2023-01-04 21:05 . 大坑解决
pipeline {
agent {
node {
label 'maven'
}
}
parameters {
string(name:'TAG_NAME',defaultValue: '',description:'')
}
environment {
DOCKER_CREDENTIAL_ID = 'aliyun-hub'
GITHUB_CREDENTIAL_ID = 'github-id'
KUBECONFIG_CREDENTIAL_ID = 'devops-kubeconfig'
REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
DOCKERHUB_NAMESPACE = 'logistics-ljj'
DOCKERHUB_REPONAME = 'xsbank'
GITHUB_ACCOUNT = 'jokerman_697'
APP_NAME = 'devops-java-sample'
}
stages {
stage ('代码检出') {
steps {
checkout(scm)
}
}
stage ('maven仓库存档') {
steps {
container ('maven') {
sh 'mvn clean -gs `pwd`/configuration/settings.xml test'
}
}
}
stage ('构建镜像快照推送') {
steps {
container ('maven') {
sh 'mvn -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME/$APP_NAME:snapshot-$BRANCH_NAME-$BUILD_NUMBER .'
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
// sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME/$APP_NAME:snapshot-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME/$APP_NAME:latest '
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME/$APP_NAME:snapshot-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME:$APP_NAME-latest '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME:$APP_NAME-latest '
}
}
}
}
// stage('推送最新镜像'){
// when{
// branch 'master'
// }
// steps{
// container ('maven') {
// sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME/$APP_NAME:snapshot-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME/$APP_NAME:latest '
// sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$DOCKERHUB_REPONAME:$APP_NAME:latest '
// }
// }
// }
stage('部署到sit环境') {
when{
branch 'master'
}
steps {
input(id: 'deploy-to-sit', message: '部署到测试环境?')
container ('maven') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
variable: 'KUBECONFIG')
]) {
// patch service
// sh 'envsubst < deploy/dev/patch-svc.yaml.tmp > deploy/dev/patch.svc.yaml'
sh 'kubectl kustomize deploy/dev | envsubst| kubectl apply -f devops-maven-sample.yaml'
}
}
}
}
stage('部署到生产环境') {
when{
expression{
return params.TAG_NAME =~ /v.*/
}
}
steps {
input(id: 'deploy-to-production', message: '部署到生产环境?')
container ('maven') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
variable: 'KUBECONFIG')
]) {
// patch service
// sh 'envsubst < deploy/prod/patch-svc.yaml.tmp > deploy/prod/patch.svc.yaml'
sh 'kubectl kustomize deploy/prod | envsubst| kubectl apply -f devops-maven-sample.yaml'
}
}
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/jokerman_697/devops-maven-sample.git
git@gitee.com:jokerman_697/devops-maven-sample.git
jokerman_697
devops-maven-sample
devops-maven-sample
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385