赞
踩
学习尚硅谷老师的课程,在此记录一下,感谢尚硅谷老师!!!
创建
基本信息的配置后,点击下一步,点击创建
![!](https://img-blog.csdnimg.cn/5d369c32b26e4aeca0b248b85222ed99.png)
配置流水线, 点击取消
点击 编辑 jenkinsfile , 开始配置流水线
Jenkinsfile 文件方式, Jenkinsfile文件为:
pipeline { agent { node { label 'maven' } } stages { stage('拉取代码') { steps { git(url: 'https://gitee.com/qinenqi/gulimall.git', credentialsId: 'gitee-id', branch: 'master', changelog: true, poll: false) sh 'echo 正在构建 $PROJECT_NAME 版本号:$PROJECT_VERSION 将会提交给 $REGISTRY 镜像仓库' container('maven') { sh 'mvn clean install -Dmaven.test.skip=true -gs `pwd`/mvn-settings.xml' } } } stage('构建镜像-推送镜像') { steps { container('maven') { sh 'mvn -Dmaven.test.skip=true -gs `pwd`/mvn-settings.xml clean package' sh 'cd $PROJECT_NAME && docker build -f Dockerfile -t $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_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/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:latest ' sh 'docker push $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('发布版本'){ steps { container ('maven') { input(id: 'release-image-with-tag', message: '发布当前版本镜像吗?') sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:$PROJECT_VERSION ' sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:$PROJECT_VERSION ' withCredentials([usernamePassword(credentialsId: "$GITEE_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { sh 'git config --global user.email "534096094@qq.com" ' sh 'git config --global user.name "leifengyang" ' 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' } } } } } environment { DOCKER_CREDENTIAL_ID = 'dockerhub-id' GITEE_CREDENTIAL_ID = 'gitee-id' KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' REGISTRY = 'docker.io' DOCKERHUB_NAMESPACE = 'qinenqi' GITEE_ACCOUNT = 'qinenqi' SONAR_CREDENTIAL_ID = 'sonar-qube' BRANCH_NAME = 'master' } parameters { string(name: 'PROJECT_VERSION', defaultValue: 'v0.0Beta', description: '项目版本') string(name: 'PROJECT_NAME', defaultValue: 'gulimall-gateway', description: '构建模块') } }
6. 点击确定
7. 开始运行流水线,打包 gulimall-gateway 项目,进行测试
点击确定
等待大约十来分钟,部署完成
https://hub.docker.com/ 项目也推送了
服务也已经部署到了k8s中了
8. 测试服务是否可用
测试成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。