• 使用Jenkins合并gitlab服务器上的代码


    1、申请gitlab读写权限账号

    2、在Jenkins的主机上,运行Jenkins程序的用户的home目录下,执行:

    touch .git-credentials
    vim .git-credentials
    http://{用户名}:{密码}@{IP地址}

    git config --global credential.helper store

    查看.gitconfig文件,有

    [credential] helper = store

    这样,操作git就不需要再输入账号密码

    3、

    a、合并分支到主干

    cat git_merge_branch_to_master.sh 
    #!/bin/bash
    RepositoryURL=$1
    Branch=$2
    ProjectName_tmp=${RepositoryURL##*/}
    ProjectName=${ProjectName_tmp%.*}
    echo $ProjectName
    echo $Branch

    nowPath=`pwd`
    rm -fr $nowPath/*
    ls
    git clone $RepositoryURL
    cd $ProjectName
    sleep 1
    git checkout -b $Branch origin/$Branch
    sleep 1
    git checkout master
    sleep 1
    git merge $Branch
    sleep 1
    git push origin master

    b、合并主干到分支

    cat git_merge_master_to_branch.sh
    #!/bin/bash
    RepositoryURL=$1
    Branch=$2
    ProjectName_tmp=${RepositoryURL##*/}
    ProjectName=${ProjectName_tmp%.*}
    echo $ProjectName
    echo $Branch

    nowPath=`pwd`
    echo $nowPath
    rm -fr $nowPath/*
    ls
    git clone -b $Branch $RepositoryURL
    cd $ProjectName
    sleep 1
    git checkout -b master origin/master
    sleep 1
    git checkout $Branch
    sleep 1
    git merge master
    sleep 1
    pwd
    #git add .
    #git commit -m "merge master to branch"
    #git push $RepositoryURL $ProjectName
    ls
    git push origin $Branch
    mv ./* .. && cd .. && rm -fr $ProjectName

    4、脚本使用,在Jenkins新建自由风格项目,在“构建”中,“增加构建步骤”,“execute shell ” 填写执行脚本的命令,例如:

    source ~/.bashrc && bash /apps/sh/git_merge_branch_to_master.sh http://10.0.0.200/dxmall/pms-service.git 20170705_shop_pms_1.5.1

    脚本执行有两个参数,第一个参数为项目的gitlab地址,第二个为分支的名字。

  • 相关阅读:
    软件推荐Q10 CircleDock PHP
    Google Chrome浏览器 扩展程序推荐 PHP
    jsColor取色器 PHP
    在线指法练习【怀旧版】 PHP
    model工厂类(转)
    表变量与临时表的优缺点
    项目的阶段性目标管理
    如何配置不启用安全的WCF服务
    团队高效执行力从何而来
    socket connect函数本质含义
  • 原文地址:https://www.cnblogs.com/hyming011/p/8252582.html
Copyright © 2020-2023  润新知