Jenkins-Pipeline 流水线发布

0.216字数 54阅读 1069

基于docker部署
1.部署jenkins

$ yum -y install  java 
$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
$ wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
$ rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
$ yum -y install jenkins 

2.部署gitlab

$ wget https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-9.1.3-ce.0.el6.x86_64.rpm
$ rpm -ivh gitlab-ce-9.1.3-ce.0.el6.x86_64.rpm
$ gitlab-ctl reconfigure
$ gitlab-ctl start

3.harbor仓库部署
http://www.unmin.club/?p=252

4.gitlab新建项目


图片.png

5.jenkins配置


图片.png

图片.png
node{
    stage('git下载'){
        //check CODE
        git credentialsId: '664b2611-19e9-458f-beba-e215bbcb96f1', url: 'git@gitlab.example.com:root/my-test.git'
    }


    stage('构建'){
        sh '''
cd /root/.jenkins/workspace/pipe/
cat >Dockerfile <<EOF
FROM tomcat:tomcat
RUN rm -rf /usr/src/tomcat/webapps/ROOT/index.jsp
COPY ./index.jsp  /usr/src/tomcat/webapps/ROOT/
WORKDIR /usr/src/tomcat
EXPOSE 9090
ENTRYPOINT ["./bin/catalina.sh", "run"]
EOF
    ''' 
    }

    stage('上传到仓库'){
        sh '''
docker build -t tomcat:2 .
docker tag tomcat:2 www.zam.com/os/tomcat:2
docker login -u admin -p Harbor12345 www.zam.com
docker push www.zam.com/os/tomcat:2
docker rmi www.zam.com/os/tomcat:2
docker rmi tomcat:2
        '''
    }   
    stage('给docker集群部署'){
        sh '''
ssh  192.168.16.238  'bash -x -s'  </root/test.sh
        '''
    }

}

6.jenkins主机编写脚本(需要源镜像tomcat)

#!/bin/bash
docker login  -u admin  -p Harbor12345  www.zam.com
docker rmi  -f www.zam.com/os/tomcat:2
docker pull  www.zam.com/os/tomcat:2
docker rm -f  tomcat
docker run -itd   --name tomcat --net host   www.zam.com/os/tomcat:2 

7.构建


图片.png

推荐阅读更多精彩内容