代码拉取完成,页面将自动刷新
同步操作将从 FenG_Vnc/devops-maven-sample 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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'
}
}
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。