zoukankan      html  css  js  c++  java
  • 使用 pipeline 实现 monitor 仓库代码的发布

    在gitlab 仓库里面编辑 jenkins file ,定义步骤

    1、在 Gitlab 在 monitor 仓库的根目录上添加 Jenkinsfile 文件,文件内容如下:

    步骤

    1.替换文件,

    2.单元测试

    3.打包

    4.deploy 部署

    5.测试

    这个没有获取源代码,因为在获取jenkins file时候 已经把源代码拉倒仓库下面

    此 jenkinsfile 包括五个 stage,分为 replace file、test、package、deploy,对于非编译项目,我们一般包括这五个阶段

    pipeline { 
        agent any 
        stages {
            stage('replace file') { 
                steps { 
                    echo "replace config file use cp " 
                } 
            }
            stage('unit test') { 
                steps { 
                    echo "unit test " 
                } 
            }
            stage('package') { 
                steps { 
                    sh 'tar czf /opt/web-${BUILD_ID}.tar.gz ./* --exclude=./git --exclude=Jenkinsfile' 
                } 
            }
            stage('deploy') { 
                steps { 
                    sh 'ssh 192.168.31.11 "cd /data/www && mkdir web-${BUILD_ID}"' 
                    sh 'scp /opt/web-${BUILD_ID}.tar.gz 192.168.31.11:/data/www/web-${BUILD_ID}' 
                    sh 'ssh 192.168.31.11 "cd /data/www/web-${BUILD_ID} && tar xf web-${BUILD_ID}.tar.gz &&rm -f web-${BUILD_ID}.tar.gz"' 
                    sh 'ssh 192.168.31.11 "cd /data/www && rm -rf html && ln -s /data/www/web-${BUILD_ID}" /data/www/html' 
                } 
            }
            stage('test') { 
                steps { 
                    echo "deploy after test " 
                } 
            }
        }
    }

    ${BUILD_ID} 是调用了环境变量,jenkins 环境变量 有个BUILD_ID 就是构建的#1 或者#2 编号
    tar 打包 排除了
    --exclude 目录下git仓库 和jenkinsfile

    在jenkins 上点击立即构建

     执行成功

    我们看到我们部署已经成功。

     
  • 相关阅读:
    区块链共识算法整理
    用Python实现GBDT算法并处理Iris数据集
    用Python实现岭回归算法与Lasso回归算法并处理Iris数据集
    软件体系结构结课报告
    用Python实现支持向量机并处理Iris数据集
    HTML标签(三)
    HTML标签(二)
    HTML标签(一)
    HTML简介
    开始。
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/12799493.html
Copyright © 2011-2022 走看看