Public | Automated Build

Last pushed: 10 months ago
Short Description
Jenkins Image
Full Description

Lesson-14 基于Docker进行CI(持续集成)

构建Jenkins镜像

sudo docker build -t "jenkins" .

启动Jenkins

sudo mkdir -p /opt/jenkins/data/workspace

jk=$(sudo docker run -d --net=host -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v /sys:/sys -v /lib64:/lib64 -v /var/lib/docker:/var/lib/docker -v /opt/jenkins/data/workspace:/opt/jenkins/data/workspace --privileged -p 8080:8080 jenkins)

sudo docker logs -f $jk

创建Jenkins任务

# 这里构建镜像,将镜像id保存到IMAGE变量中
IMAGE=$(docker build . | tail -1 | awk '{ print $NF }')

# 启动容器,容器ID放到CONTAINER中
CONTAINER=$(docker run -d -v "$WORKSPACE:/opt/project" $IMAGE /bin/bash -c "cd /opt/project && rake spec")

# 取得容器的返回值(正常退出为0)
RC=$(docker wait $CONTAINER)

# 测试结束后删除容器
docker rm $CONTAINER


# 镜像可根据情况选择是否删除
docker rmi -f $IMAGE

# 返回值传回给Jenkins
exit $RC

对docker101-sample-gem进行测试

删除Jenkins容器

sudo docker kill $jk

视频地址

Docker Pull Command
Owner
liubin
Source Repository

Comments (0)