在jenkins下,点击项目->配置 tab里点 流水线
写一步,测一步
坑1:由于安装jenkins时没有找到mvn插件,所以提示mvn命令不存在,需要再安装一下,安装完重启
坑2.对于java web 多模块项目,要改一下父工程下pom,module的路径./
ylk-security-core等
坑3:jenkins服务器下的docker ->/etc/docker/daemon.json,以及harbor下的docker ->/etc/docker/daemon.json,都要进行
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxx.mirror.aliyuncs.com"],
"insecure-registry": ["192.168.0.91:5000"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
注意:安装jenkins这台机器上也要安装docker
#!groovy
pipeline {
agent any
environment {
REPOSITORY="ssh://git@192.168.0.91:2222/ckip/cd_project.git"
SHELL_PATH="/usr/local/myshell"
MODULE="ylk-server"
}
stages {
stage('获取代码为mvn构建') {
steps {
echo "start fetch code from git:${REPOSITORY}"
deleteDir()
git "${REPOSITORY}"
}
}
stage('代表静态检查') {
steps {
echo "start code check"
}
}
stage('使用mvn打包编译+单元测试') {
steps {
echo "start compile"
sh "mvn clean package -Dmaven.test.skip=true"
}
}
stage('构建image') {
steps {
echo "start build image"
sh "${SHELL_PATH}/build-image.sh ${MODULE}"
}
}
}
}
build-image.sh 在对应文件下用vim创建,并且chmod
#!/bin/bash
MODULE=$1
TIME=`date "+%Y%m%d%H%M"`
GIT_VERSION=`git log -1 --pretty=format:"%h"`
IMAGE_NAME=192.168.0.91/cd_project/${MODULE}:${TIME}_${GIT_VERSION}
cd ${MODULE}
docker build -t ${IMAGE_NAME} .
docker login 192.168.0.91 -u lhbjava -p Harbor12345
docker push ${IMAGE_NAME}
posted on 2018-05-29 14:00
长春语林科技 阅读(324)
评论(0) 编辑 收藏 所属分类:
docker