加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile-for-k8s 6.02 KB
一键复制 编辑 原始数据 按行查看 历史
Allen 提交于 2018-12-27 09:27 . 增加向阿里云推送chart
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()
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化