forked from xix-team/ci-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect
executable file
·19 lines (14 loc) · 1.05 KB
/
detect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env bash
# @author [email protected]
# @version 0.1.0
# @update 2016-10-20
# @description 服务环境,脚本会自动根据env_rule计算ref对应的服务环境, dev=开发环境 sit=系统集成测试环境 uat=用户验收测试环境 prd=生产环境
# eg: `./detect master`
# eg: $(/opt/ci-shell/detect origin/develop)
origin=${!#}
# 转换ref为最后两位,并且把/替换为-
ref=$(echo $origin | awk '{gsub(/(refs|remotes|origin|heads|tags)\//, "");print $0;}' | awk '{gsub(/\//, "-");print $0;}')
# 计算服务环境,ref对应服务环境的规则
# env=$(echo $ref | awk --posix '{if($0~/^[0-9]+(\.[0-9]+){1,3}$/){i="prd"}else if($0~/^master/){i="uat"}else if($0~/^(release|hotfix|uat)/){i="uat"}else if($0~/^develop/){i="sit"}else if($0~/^hotfix/){i="uat"}else if($0~/^feature$/){i="dev"}print i}' )
env=$(echo $ref | awk --posix '{if($0~/^[0-9]+(\.[0-9]+){1,3}$/){i="prd"}else if($0~/^prd/){i="prd"}else if($0~/^master/){i="uat"}else if($0~/^uat/){i="uat"}else if($0~/^sit/){i="sit"}else if($0~/^develop/){i="dev"}print i}' )
echo $env