1 Star 0 Fork 0

Hadit/gulimall

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile-build 4.26 KB
一键复制 编辑 原始数据 按行查看 历史
Hadit 提交于 2021-10-06 14:10 . update Jenkinsfile-build.
pipeline {
agent {
node {
label 'maven'
}
}
environment {
DOCKER_CREDENTIAL_ID = 'alihub-id'
GITEE_CREDENTIAL_ID = 'gitee-id'
KUBECONFIG_CREDENTIAL_ID = 'gulimall-kubeconfig'
REGISTRY = 'registry.cn-heyuan.aliyuncs.com'
DOCKERHUB_NAMESPACE = 'cwgulimall'
GITEE_ACCOUNT = 'a14334861'
SONAR_CREDENTIAL_ID = 'sonar-token'
BRANCH_NAME = 'master'
}
stages {
stage('拉取代码') {
steps {
git(url: 'https://gitee.com/a14334861/gulimall.git', credentialsId: 'gitee-id', branch: 'master', changelog: true, poll: false)
sh 'echo 正在构建 $PROJECT_NAME 版本号:$PROJECT_VERSION'
container('maven') {
sh "mvn clean install package -Dmaven.test.skip=true -gs `pwd`/mvn-settings.xml"
}
}
}
stage('构建镜像') {
steps {
container('maven') {
sh 'cd $PROJECT_NAME && docker build -f Dockerfile -t $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:$PROJECT_VERSION '
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:latest '
}
}
}
stage('是否部署到k8s?') {
steps {
input(id: "deploy-to-dev-$PROJECT_NAME", message: "是否将 $PROJECT_NAME 部署到集群中?")
kubernetesDeploy(configs: "$PROJECT_NAME/deploy/**", enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
}
}
stage('是否发布版本到gitee/github?') {
when {
expression {
return params.PROJECT_VERSION =~ /v.*/
}
}
steps {
container('maven') {
input(id: 'release-with-tag', message: '推送到gitee/github吗?')
withCredentials([usernamePassword(credentialsId: "$GITEE_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh 'git config --global user.email "282991955@qq.com" '
sh 'git config --global user.name "cw" '
sh 'git tag -a $PROJECT_NAME-$PROJECT_VERSION -m "$PROJECT_VERSION" '
sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@gitee.com/$GITEE_ACCOUNT/gulimall.git --tags --ipv4'
}
}
}
}
stage('是否推送镜像到镜像仓库?') {
when {
expression {
return params.PROJECT_VERSION =~ /v.*/
}
}
steps {
container('maven') {
input(id: 'release-image-with-tag', message: '发布当前版本镜像吗?')
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 push $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:$PROJECT_VERSION '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:latest '
}
}
}
}
}
parameters {
string(name: 'PROJECT_VERSION', defaultValue: 'v0.1', description: '项目版本')
choice(
description: '请选择需要构建或更新的模块',
name: 'PROJECT_NAME',
choices: ['gulimall-gateway', 'gulimall-product', 'gulimall-search', 'gulimall-member', 'gulimall-auth-server', 'gulimall-cart', 'gulimall-order', 'gulimall-seckill', 'gulimall-coupon', 'gulimall-third-party', 'gulimall-ware', 'renren-fast']
)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/a14334861/gulimall.git
git@gitee.com:a14334861/gulimall.git
a14334861
gulimall
gulimall
master

搜索帮助