代码拉取完成,页面将自动刷新
同步操作将从 微服务团队/网关服务 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
pipeline {
agent {
label "jenkins-maven"
}
options{
buildDiscarder(logRotator(numToKeepStr: '3'))//最多保留3次构建结果
timeout(time: 1, unit: 'HOURS')
}
parameters {
booleanParam(name: 'dev_spaces', defaultValue: true, description: '部署开发环境,仅对RP分支生效')
booleanParam(name: 'preview_spaces', defaultValue: false, description: '部署集成环境,仅对RP分支生效')
}
environment {
//ORG为整体项目名称,例示:klx为产品项目
ORG = 'klx'
//APP_NAME为该项目的的名称,也为镜像的名称
APP_NAME = 'ms-gateway'
CHARTMUSEUM_CREDS = credentials('chartmuseum')
PREVIEW_NAMESPACE = "preview"
TEST_NAMESPACE = "test"
DEV_NAMESPACE = "dev"
}
stages {
stage('CI Build and push snapshot') {
when {
branch 'PR-*'
}
environment {
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
//PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
projectpom = readMavenPom file: 'pom.xml'
projectArtifactId = projectpom.getArtifactId()
}
steps {
container('maven') {
sh "mvn versions:set -DnewVersion=$PREVIEW_VERSION"
sh "mvn package -Dmaven.test.skip=true"
sh 'export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold-dev.yaml'
//sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
}
script {
if(dev_spaces == 'true'){
dir ('./charts/dev') {
container('maven') {
sh "export FILE_NAME=$projectArtifactId && export NAMESPACE=$DEV_NAMESPACE && make preview"
sh "helm template -n $DEV_NAMESPACE --output-dir . . "
sh "kubectl apply -f ./$DEV_NAMESPACE/charts/$projectArtifactId/templates/ -n $DEV_NAMESPACE "
//sh "helm upgrade --namespace $DEV_NAMESPACE --install --wait --force --timeout 600 dev-$projectArtifactId ."
//sh 'export CHART_REPOSITORY=$CHARTMUSEUM_REPO && jx step helm apply --name $webgateArtifactId --dir . --namespace my-preview'
//sh "jx preview --app $APP_NAME --dir ../.."
//sh 'kubectl delete configmap exposecontroller -n $DEV_NAMESPACE'
}
}
}
if(preview_spaces == 'true'){
dir ('./charts/preview') {
container('maven') {
sh "export FILE_NAME=$projectArtifactId && export NAMESPACE=$PREVIEW_NAMESPACE && make preview"
sh "helm template -n $PREVIEW_NAMESPACE --output-dir . . "
sh "kubectl apply -f ./$PREVIEW_NAMESPACE/charts/$projectArtifactId/templates/ -n $PREVIEW_NAMESPACE "
//sh "helm upgrade --namespace $PREVIEW_NAMESPACE --install --wait --force --timeout 600 pre-$projectArtifactId ."
//sh 'export CHART_REPOSITORY=$CHARTMUSEUM_REPO && jx step helm apply --name $webgateArtifactId --dir . --namespace my-preview'
//sh "jx preview --app $APP_NAME --dir ../.."
//sh 'kubectl delete configmap exposecontroller -n $PREVIEW_NAMESPACE'
}
}
}
}
}
}
stage('Build Release') {
when {
branch 'master'
}
environment {
projectpom = readMavenPom file: 'pom.xml'
projectArtifactId = projectpom.getArtifactId()
}
steps {
container('maven') {
// ensure we're not on a detached head
sh "git checkout master"
sh "git config --global credential.helper store"
sh "jx step git credentials"
// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
sh "mvn versions:set -DnewVersion=\$(cat VERSION)"
}
dir ('./charts/ms-gateway') {
container('maven') {
sh "export FILE_NAME=$projectArtifactId && export NAMESPACE=$TEST_NAMESPACE && make tag"
}
}
container('maven') {
sh 'mvn clean package -Dmaven.test.skip=true'
sh 'export VERSION=`cat VERSION` && export FILE_NAME=$projectArtifactId && skaffold build -f skaffold.yaml'
sh 'export VERSION=`cat VERSION` && docker tag $DOCKER_REGISTRY/$ORG/$projectArtifactId:$VERSION $DOCKER_REGISTRY_ALIYUN/kms/$projectArtifactId:$VERSION'
sh 'export VERSION=`cat VERSION` && docker push $DOCKER_REGISTRY_ALIYUN/kms/$projectArtifactId:$VERSION'
//sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
}
}
}
stage('Promote to Environments') {
environment {
projectpom = readMavenPom file: 'pom.xml'
projectArtifactId = projectpom.getArtifactId()
}
when {
branch 'master'
}
steps {
dir ('./charts/ms-gateway') {
container('maven') {
//sh 'jx step changelog --version v\$(cat ../../VERSION)'
// release the helm chart
//sh 'export CHART_REPOSITORY=$CHARTMUSEUM_REPO && jx step helm release'
sh 'export FILE_NAME=$projectArtifactId && make release'
sh "helm template -n $TEST_NAMESPACE --output-dir . . "
sh "kubectl apply -f ./$projectArtifactId/templates/ -n $TEST_NAMESPACE "
//sh "helm upgrade --namespace $TEST_NAMESPACE --install --wait --force --timeout 600 test-$projectArtifactId ."
//sh 'export CHART_REPOSITORY=$CHARTMUSEUM_REPO && jx step helm apply --name $projectArtifactId --dir . --namespace ${TEST_NAMESPACE}'
// promote through all 'Auto' promotion Environments
//sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)'
}
}
}
}
}
post {
always {
cleanWs()
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。