一、背景

打包需要交互式进行,同时集成至jenkins后就无法捕获正常信息,无奈只能调试脚本打包

二、脚本

#!/bin/bash
#WPS前端一键打包
#Author: yousong.xiang
#Date:  2020.9.15
#Version: v1.0.1

[ -f /etc/profile ] && . /etc/profile
if [ # -ne 2 ]; then
    echo "USAGE:{\$1 \$2}"
else
    release_tag=1
    url=2
fi

git_22_url='ssh://git@192.168.254.22:11022/xc-front/wps_front.git'
git_38_url='ssh://git@192.168.254.38/xcadmin/xunce-spec.git'
git_deploy_url='ssh://git@192.168.254.38/ops/wps-front.git'
# url='http://192.168.20.120/data/wps/publish/'
buildrootdir=/tmp/BUILDROOT
builddir=/tmp/ddd/wps_front
specdir=/tmp/SPECS
rpmdir=/tmp/RPMS

#定义rpmbuild的环境变量位置
[ -dbuildrootdir ] && rm -rf buildrootdir
[ -dbuilddir ] && rm -rf builddir
[ -dspecdir ] && rm -rf specdir
[ -drpmdir ] && rm -rf rpmdir
mkdir -pbuildrootdir
mkdir -p builddir
mkdir -pspecdir
mkdir -p rpmdir

function pull_git() {
    set -eux
    git_url=1
    dev_tag=2
    project=`echo{1##*/}|cut -d '.' -f 1`
    if [ -d project ]; then
        rm -rfproject
    fi
    git clone --depth 1 --branch={dev_tag}{git_url} ./{project}
}

#rpm打包函数
function rpm_spec_build() {
    set -eux
    git_project=`echo{git_22_url##*/}|cut -d '.' -f 1`
    spec_project=`echo {git_38_url##*/}|cut -d '.' -f 1`
    cp -rgit_project/* builddir/
    rpm_tag=`echorelease_tag|sed 's@^v@@g'`
    host_ip=`echo url|grep -Eo '[0-9]{2,3}.[0-9]{2,3}.[0-9]{2,3}.[0-9]{2,3}'`
    cdspec_project
    sed -i "/^%define WPS_FRONT_VERSION/c%define WPS_FRONT_VERSION {rpm_tag}_{host_ip}" wps_front.spec
    rpmbuild --define "_buildrootdir {buildrootdir:-/tmp/BUILDROOT}" \
    --define "_builddir{builddir:-/tmp/ddd/wps_front}" \
    --define "_specdir {specdir:-/tmp/SPECS}" \
    --define "_rpmdir{rpmdir:-/tmp/RPMS}" \
    -bb wps_front.spec
    cd -
    set +eux
}

function push_deploy() {
    set -eux
    deploy_project=`echo {git_deploy_url##*/}|cut -d '.' -f 1`
    git_project=`echo{git_22_url##*/}|cut -d '.' -f 1`
    rpm_tag=`echo release_tag|sed 's@^v@@g'`
    cddeploy_project
    tag_num=(git tag -l{release_tag}|wc -l)

    git config user.name 'ops'
    git config user.email 'ops@xuncetech.com'
    if [ {tag_num} -eq 1 ]; then
        echo "release tag{release_tag} 存在,正在删除..."
        git tag -d {release_tag}
        git push origin --delete{release_tag}
    fi
    cp rpmdir/x86_64/wps-front-{rpm_tag}-1.el7.x86_64.rpm ./
    cd -
    cp -rf git_project/doc ./deploy_project/
    cd deploy_project
    echo{release_tag} >version
    git add .
    git commit -m {release_tag}
    git tag -a{release_tag} -m "jenkins 自动打包tag {release_tag}"
    git push --tags -f
    cd -
    set +eux
}

function install_expect() {
    url=1
    [ -f front.exp ] && rm -rf front.exp
    cat>>front.exp<<EOF
#!/usr/bin/expect
set url http://192.168.20.99/data/wps/publish/

spawn wpsjs publish

expect ":" { send "\url\r"}

expect "❯" { send "\r" }

interact
EOF
    chmod a+x front.exp
    sed -i "/set url/cset urlurl" front.exp
}



#1.拉取多个仓库代码文件
pull_git git_22_urlrelease_tag
pull_git git_38_url master
pull_gitgit_deploy_url master

#2.配置交互式脚本
install_expect url
git_project=`echo{git_22_url##*/}|cut -d '.' -f 1`
[ -f front.exp ] && mv front.exp $git_project/

#3.rpmbuild操作
rpm_spec_build

#3.push rpm版本包到rpm包仓库
push_deploy


最后修改日期: 2023年12月16日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。