一起学CICD 08.gitlab+jenkins+maven+sonar+nodejs pipeline构建

gitlab+jenkins+maven+sonar+nodejs pipeline

环境

iphostnamesoft
192.168.48.52gitlabgitlab
192.168.48.53jenkinsjdk1.8,jenkins,maven,nodejs,sonar
192.168.48.56webjdk1.8 nginx mysql

原项目下载

[root@gitlab home]# pwd
/home
[root@gitlab home]# git clone https://github.com/callicoder/spring-security-react-ant-design-polls-app.git
[root@gitlab home]# ll
total 0
drwxr-xr-x 6 root root 192 Aug 25 23:51 spring-security-react-ant-design-polls-app
[root@gitlab spring-security-react-ant-design-polls-app]# ll
total 320
drwxr-xr-x 2 root root    123 Aug 25 23:51 deployments
-rw-r--r-- 1 root root   1962 Aug 25 23:51 docker-compose.yml
-rw-r--r-- 1 root root     75 Aug 25 23:51 minikube.txt
drwxr-xr-x 4 root root    212 Aug 25 23:51 polling-app-client
drwxr-xr-x 4 root root    108 Aug 25 23:51 polling-app-server
-rw-r--r-- 1 root root   2657 Aug 25 23:51 Readme.md
-rw-r--r-- 1 root root 314392 Aug 25 23:51 screenshot.png

gitlab

创建polling-app-server

在这里插入图片描述

在这里插入图片描述

[root@gitlab ~]# git clone git@192.168.48.52:test01/polling-app-server.git
Cloning into 'polling-app-server'...
warning: You appear to have cloned an empty repository.

[root@gitlab ~]# cd /home/spring-security-react-ant-design-polls-app/polling-app-server/
[root@gitlab polling-app-server]# ll -a
total 28
drwxr-xr-x 4 root root  108 Aug 25 23:51 .
drwxr-xr-x 6 root root  192 Aug 25 23:51 ..
-rw-r--r-- 1 root root 1038 Aug 25 23:51 Dockerfile
-rw-r--r-- 1 root root  419 Aug 25 23:51 .gitignore
drwxr-xr-x 3 root root   21 Aug 25 23:51 .mvn
-rwxr-xr-x 1 root root 6468 Aug 25 23:51 mvnw
-rw-r--r-- 1 root root 4994 Aug 25 23:51 mvnw.cmd
-rw-r--r-- 1 root root 2417 Aug 25 23:51 pom.xml
drwxr-xr-x 4 root root   30 Aug 25 23:51 src
[root@gitlab polling-app-server]# rm -rf .gitignore 
[root@gitlab polling-app-server]# mv * /root/polling-app-server/
[root@gitlab ~]# cd /root/polling-app-server/
[root@gitlab polling-app-server]# ll
total 24
-rw-r--r-- 1 root root 1038 Aug 25 23:51 Dockerfile
-rwxr-xr-x 1 root root 6468 Aug 25 23:51 mvnw
-rw-r--r-- 1 root root 4994 Aug 25 23:51 mvnw.cmd
-rw-r--r-- 1 root root 2417 Aug 25 23:51 pom.xml
drwxr-xr-x 4 root root   30 Aug 25 23:51 src
[root@gitlab polling-app-server]# git add .
[root@gitlab polling-app-server]# git commit -m "server"
[root@gitlab polling-app-server]# git push origin master

在这里插入图片描述

创建polling-app-client

在这里插入图片描述

[root@gitlab ~]# git clone git@192.168.48.52:test01/polling-app-client.git
Cloning into 'polling-app-client'...
warning: You appear to have cloned an empty repository.

[root@gitlab polling-app-client]# cd /home/spring-security-react-ant-design-polls-app/polling-app-client/
[root@gitlab polling-app-client]# ll -a
total 832
drwxr-xr-x 4 root root    212 Aug 25 23:51 .
drwxr-xr-x 6 root root    192 Aug 25 23:51 ..
-rw-r--r-- 1 root root    548 Aug 25 23:51 config-overrides.js
-rw-r--r-- 1 root root   1036 Aug 25 23:51 Dockerfile
-rw-r--r-- 1 root root     24 Aug 25 23:51 .dockerignore
-rw-r--r-- 1 root root    285 Aug 25 23:51 .gitignore
-rw-r--r-- 1 root root   1898 Aug 25 23:51 nginx.conf
-rw-r--r-- 1 root root    561 Aug 25 23:51 package.json
-rw-r--r-- 1 root root 446289 Aug 25 23:51 package-lock.json
drwxr-xr-x 2 root root     64 Aug 25 23:51 public
-rw-r--r-- 1 root root 119004 Aug 25 23:51 README.md
drwxr-xr-x 8 root root    181 Aug 25 23:51 src
-rw-r--r-- 1 root root 258001 Aug 25 23:51 yarn.lock
[root@gitlab polling-app-client]# rm -rf .gitignore 
[root@gitlab polling-app-client]# mv * /root/polling-app-client/

[root@gitlab ~]# cd /root/polling-app-client/
[root@gitlab polling-app-client]# ll
total 824
-rw-r--r-- 1 root root    548 Aug 25 23:51 config-overrides.js
-rw-r--r-- 1 root root   1036 Aug 25 23:51 Dockerfile
-rw-r--r-- 1 root root   1898 Aug 25 23:51 nginx.conf
-rw-r--r-- 1 root root    561 Aug 25 23:51 package.json
-rw-r--r-- 1 root root 446289 Aug 25 23:51 package-lock.json
drwxr-xr-x 2 root root     64 Aug 25 23:51 public
-rw-r--r-- 1 root root 119004 Aug 25 23:51 README.md
drwxr-xr-x 8 root root    181 Aug 25 23:51 src
-rw-r--r-- 1 root root 258001 Aug 25 23:51 yarn.lock

[root@gitlab polling-app-client]# git add .
[root@gitlab polling-app-client]# git commit -m "client"
[root@gitlab polling-app-client]# git push origin master

web

安装nginx

[root@web ~]# yum -y install nginx

创建数据库

mysql> CREATE DATABASE polling_app CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all privileges on *.* to 'root'@'%' identified by 'p@ssW0rd';

jenkins

nodejs 配置

[root@jenkins home]# ll
-rw-r--r--  1 root  root   13832768 Aug 19 12:58 node-v12.8.1-linux-x64.tar.xz

[root@jenkins home]# tar xvf node-v12.8.1-linux-x64.tar.xz

[root@jenkins ~]# vim /etc/profile
...
export NODE_HOME=/home/node-v12.8.1-linux-x64
export PATH=$NODE_HOME/bin:$PATH

[root@jenkins ~]# source /etc/profile
[root@jenkins ~]# npm -v
6.10.2

jenkins用户

[root@jenkins ~]# vim /etc/passwd
....
jenkins:x:998:996:Jenkins Automation Server:/var/lib/jenkins:/bin/bash

[root@jenkins ~]# echo "jenkins" | passwd jenkins --stdin

[root@jenkins ~]# su - jenkins
[jenkins@jenkins ~]$echo "export PS1='[\u@\h \W]\$'" > .bash_profile 
[jenkins@jenkins ~]$source .bash_profile 

pipeline

gitlabd的私钥

在这里插入图片描述

polling-app-server

在这里插入图片描述

node () {
def workspace = pwd()
def password = "nmslwsnd0928"
def mysql_password = "p@ssW0rd"
def host = "192.168.48.56"
def git_url = "git@192.168.48.52:test01/polling-app-server.git"
    
    stage 'checkout'
    dir('server'){
     git branch: 'master', credentialsId: '6814bf41-71da-404e-8244-d1138605fca8', url: "${git_url}"
     }
     
    stage 'Build'
       
    sh"""
         source /etc/profile
         cd $workspace/server
         sed -i "s/localhost/${host}/g" src/main/resources/application.properties
         sed -i "s/callicoder/${mysql_password}/g" src/main/resources/application.properties
         /home/apache-maven-3.6.1/bin/mvn clean package sonar:sonar
     """
    stage 'upload'
    
    sh """
        sshpass -p${password} scp $workspace/server/target/polls-0.0.1-SNAPSHOT.jar  root@${host}:/data
    """
    
    stage "start"
     sh """
        sshpass -p${password} ssh  root@${host} 'echo "pkill java;source /etc/profile;nohup java -jar /data/polls-0.0.1-SNAPSHOT.jar 1 > app.log 2>&1 &" > /data/start.sh'
        sshpass -p${password} ssh  root@${host} 'bash /data/start.sh'
    """
}

在这里插入图片描述

polling-app-client

在这里插入图片描述

node () {
def workspace = pwd()
def password = "nmslwsnd0928"
def host = "192.168.48.56"
def git_url = "git@192.168.48.52:test01/polling-app-client.git"

    stage 'checkout'
    dir('client'){
     git branch: 'master', credentialsId: '6814bf41-71da-404e-8244-d1138605fca8', url: "${git_url}"
 
     }
     
    stage 'Build'
       
    sh"""
         source /etc/profile
         cd $workspace/client
         sed -i "s/localhost/${host}/" src/constants/index.js
         npm install
         npm run build
     """
    
    stage 'upload'
    
    sh """
        sshpass -p${password} ssh  root@${host} 'rm -rf /usr/share/nginx/html/*' 
        sshpass -p${password} scp -r /var/lib/jenkins/workspace/polling-app-client/client/build/*  root@${host}:/usr/share/nginx/html/
        sshpass -p${password} ssh  root@${host} 'nginx -s reload'
    """
}

在这里插入图片描述

构建

构建polling-app-server

在这里插入图片描述

在这里插入图片描述

构建polling-app-client

在这里插入图片描述

在这里插入图片描述

访问

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值