李明
|
了解git代码提交完成jenkins的构建
image.png
构建说明
#!groovy pipeline { //之前说过jenkins是支持集群的,但是咱们这里不需要集群的方式,因为有了k8s。any在任何可用的agent 上执行 agent any //环境变量, environment { REPOSITORY="ssh://git@192.168.66.101:2222/liming/microservice.git" } //流水线是如何提前,都是通过很多个stages下面的stage stages { stage('获取代码'){ steps{ echo " start fetch code from git ssh://git@192.168.66.101:2222/liming/microservice.git" deleteDir() git "${REPOSITORY}" } } } }
docker ps docker exec -it d918e00a583f /bin/bash ssh-keygen -t rsa -C "394498036@qq.com" cat /root/.ssh/id_rsa.pub
echo "nameserver 8.8.8.8" | tee /etc/resolv.conf > /dev/null apt-get update apt-get install vim cd /opt/maven/conf vi settings.xml mkdir /usr/lib/jvm/java-8-openjdk-amd64/lib
<mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project message-thrift-service-api: Compilation failure [ERROR] Unable to locate the Javac Compiler in: [ERROR] /usr/lib/jvm/java-8-openjdk-amd64/jre/../lib/tools.jar [ERROR] Please ensure you are using JDK 1.4 or above and [ERROR] not a JRE (the com.sun.tools.javac.Main class is required). [ERROR] In most cases you can change the location of your Java [ERROR] installation by setting the JAVA_HOME environment variable.
yum install lrzsz#rz 选择tool.jardocker cp tool.jar 容器ID:/usr/lib/jvm/java-8-openjdk-amd64/jre/../lib/tools.jar ··· ![](https://upload-images.jianshu.io/upload_images/11223715-27d864caa1b8bffa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) >配置环境变量 ``` bash docker exec -it 容器ID /bin/bash vi ~/.bashrc#配置下面的环境变量set JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export PATH=${JAVA_HOME}/bin:$PATH
#!groovypipeline { //之前说过jenkins是支持集群的,但是咱们这里不需要集群的方式,因为有了k8s。any在任何可用的agent 上执行 agent any //环境变量, environment { REPOSITORY="ssh://git@192.168.66.101:2222/liming/microservice.git" MODULE="user-edge-service" } //流水线是如何提前,都是通过很多个stages下面的stage stages { stage('获取代码'){ steps{ echo " start fetch code from git ssh://192.168.66.101:2222/liming/microservice.git" deleteDir() git "${REPOSITORY}" } } stage('编译+单元测试') { steps{ echo " start compile" sh "mvn -U -pl ${MODULE} -am clean package" } } } }
jenkins完成推送到官网镜像
cd ~ vi build-image.sh chmod 775 build-image.sh docker login
#!groovypipeline { //之前说过jenkins是支持集群的,但是咱们这里不需要集群的方式,因为有了k8s。any在任何可用的agent 上执行 agent any //环境变量, environment { REPOSITORY="ssh://git@192.168.66.101:2222/liming/microservice.git" MODULE="user-edge-service" SCRIPT_PATH="/root/" } //流水线是如何提前,都是通过很多个stages下面的stage stages { stage('获取代码'){ steps{ echo " start fetch code from git ssh://192.168.66.101:2222/liming/microservice.git" deleteDir() git "${REPOSITORY}" } } stage('代码静态检查') { steps{ echo " start code check" } } stage('编译+单元测试') { steps{ echo " start compile" sh "mvn -U -pl ${MODULE} -am clean package" } } stage('构建镜像') { steps{ echo " start build image" sh "#{SCRIPT_PATH}/build-image.sh ${MODULE}" } } stage('发布系统') { steps{ echo " start deploy" sh "#{SCRIPT_PATH}/deploy.sh ${MODULE} ${MODULE}" } } } }
#!/bin/bash MODULE=$1 TIME=`date "+%Y%m%d%H%M"` GIT_REVISION=`git log -1 --pretty=format:"%h"` IMAGE_NAME=zhugeaming/${MODULE}:${TIME}_${GIT_REVISION} cd ${MODULE} docker build -t ${GIT_REVISION} . docker push ${GIT_REVISION}
#!/bin/bash IMAGE=`cat IMAGE_NAME` DEPLOYMENT=$1 MODULE=$2 echo "update image to ${IMAGE}" kubectl set image deployment/${DEPLOYMENT} ${MODULE} =${MODULE} PS:最后总结下,建议jenkins不要使用容器安装,我用容器安装入了至少十几个坑,对了解命令还是有好处的。我总结几点
|
2019-03-11 09:10:11