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 参数可以看到推送事件所属那个分支

  • 相关阅读:
    9-day9-生成器-列表解析-三元表达式-
    8-day8-列表解析-装饰器-迭代器
    7-day7-闭包函数-装饰器-函数2
    6-day6-函数-1
    5-day5-字符编码-函数-文件操作
    hive 跨年周如何处理
    nginx 安装部署
    logstash 读取kafka output ES
    leedcode 001 之 Two Sum 42.20% Easy
    大数据调度与数据质量的重要性
  • 原文地址:https://www.cnblogs.com/xdtx/p/9515964.html
Copyright © 2011-2022 走看看