配置 jenkins + gitlab CICD
1、创建微服务
这个项目是一个聚合项目的聚合项目,首先是 runa-cloud-common 项目,它下面有多个项目,
其中 runa-cloud-file-center 是当前流水线要构建的项目,runa-cloud-file-application 是当前项目启动类所在的子项目
2、添加Dockerfile
#FROM openjdk:8 FROM openjdk:8-jdk # copy arthas COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas ENV SPRING_PROFILES_ACTIVE="dev" RUN echo "Asia/Shanghai" > /etc/timezone RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN mkdir /runa WORKDIR /runa ADD /runa-cloud-file-application.jar . VOLUME /runa ENTRYPOINT java -jar runa-cloud-file-application.jar --spring.profiles.active=${SPRING_PROFILES_ACTIVE}
3、配置jenkins
记住这里的url,gitlab中需要配置这个url
jar包构建后存放的目录:runa-cloud-common\runa-cloud-file-center\runa-cloud-file-application\target
拉取代码只能拉取gitlab中的根项目,子目录是没有.git url 的
但是deploy代码是可以只构建自己想要构建的代码的,当前目录是 runa-cloud-common ,
黄色部分的代码可以先 cd 到 runa-cloud-file-center 文件夹,针对这个项目路径下的pom文件构建 file-center 这一个项目
node{ def git_auth = "Git_YWF" def git_branch = "*/develop" def git_timeout = "120" def git_url = "http://192.168.1.70:8088/smart_coding/smart_coding_framework/runa-cloud-common.git" // install Maven and add it to the path env.PATH = "${tool 'M3'}/bin:${env.PATH}" stage("Code"){ checkout([ $class: 'GitSCM', branches: [[name: "${git_branch}"]], extensions: [[ $class: 'CloneOption', noTags: false, reference: '', shallow: false, timeout: "${git_timeout}" ]], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]] ]) } stage('Maven Deploy'){ configFileProvider( [configFile(fileId: 'sc_maven_settings', variable: 'MAVEN_SETTINGS')]) { sh "mvn clean deploy -Dmaven.test.skip=true -s $MAVEN_SETTINGS" } } stage('Image Deploy'){ sh ''' cd runa-cloud-file-center/runa-cloud-file-application/target docker build -t 192.168.1.61:5000/runa-cloud-file-application . docker push 192.168.1.61:5000/runa-cloud-file-application ''' sh "docker rm -f runa-cloud-file-application" sh "docker rmi \$(docker images | grep runa-cloud-file-application | awk '{print \$3}')" } stage("SIT Deploy(154)"){ def remote = [:] remote.name = 'SIT_154' remote.host = '192.168.1.154' remote.allowAnyHosts = true withCredentials([usernamePassword(credentialsId: 'SSH_137', passwordVariable: 'password', usernameVariable: 'username')]) { remote.user = "${username}" remote.password = "${password}" } sshCommand remote: remote, command: ''' docker rm -f runa-cloud-file-application docker volume rm runa-cloud-file-application_data docker rmi 192.168.1.61:5000/runa-cloud-file-application docker run -d --net=host --restart=on-failure:1 --name runa-cloud-file-application 192.168.1.61:5000/runa-cloud-file-application ''' } }
4、gitlab配置
结束