zoukankan      html  css  js  c++  java
  • 基于 Webhooks gitlab 自动化构建

    基于gitlab webhooks 自动构建流程

    1、服务器安装 git 服务

    安装成功

    配置 PHP 脚本:

    <?php
            // 接受头部信息
            if (!isset($_GET['youparam'])) {
                logs('youparamnot isset');
                exit();
            }
    
            if ($_GET['youparam'] != 'qiuxue666') {
                logs('youparamnot neq key');
                exit();
            }
    
            // 接受参数
            $datas = file_get_contents('php://input', 'r');;
            $datas = json_decode($datas,true);
    
            // 参数配置
            $brand    = 'master';
            $execName = './exce_' . $brand .'.sh';
    
            $brands = 'refs/heads/' . $brand;
            if(isset($datas['ref']) && $datas['ref'] == $brands){
    
                $result = exec($execName);
                // logs(" exec result: " . $result);
    
            }
            logs($datas['user_name'] . " commit to branch:" . $brand);
    
            function logs ($data) {
                $text    = '[' . date('Y-m-d H:i:s') .'] ' . $data . PHP_EOL;
                file_put_contents('./log/gitlab'.date('md') . '.log', $text,FILE_APPEND);
            }
    
    ?>

     shell 脚本编写:

    #!/bin/sh
    

    #php shell脚本目录 path="/data/wwwroot/objpath"
    #项目脚本目录(要判断的目录)
    objpath="/data/wwwroot/objpath/obj" if [ -d "$objpath" ]; then cd "$objpath" git pull else cd "$path" # 拉取 master     git clone -b master git@gitlab.com:youname/youobj.git fi

    gitlab 配置webhooks:

    webhooks 推送的一些参数(具体可写入日志查看):

    ref 参数可以看到推送事件所属那个分支

  • 相关阅读:
    类中代码执行顺序 及 组合
    初识面向对象
    内置函数及匿名函数 补充
    生成器 补充
    再回首 基本数据类型和 if语句
    day 023-python 包
    day022 python (re模块和 模块)
    day021python 正则表达式
    day 020 常用模块02
    android studio 菜鸟实战项目 之 点击事件以及动态添加
  • 原文地址:https://www.cnblogs.com/xdtx/p/9515964.html
Copyright © 2011-2022 走看看