Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

绿色网站无广告
会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux培训 > » 正文

shell -- jenkins build后自动上传最新war到ftp

来源: 未知 分享至:
这是我写的第一个shell,分为2部分:
1. uploadSearchAutomatically.sh
#!/bin/bash
# Program:
#       This program uploads recent search war to ftp
# History:
#       2011/10/31      Owen.Chen       First Release

# jenkins自动构建搜索项目成功后,自动在$WORKSPACE中查找indexer.war和searcher.war,再解析出上传ftp的source和destination,最后连接ftp上传

# find two war of indexer and searcher in $WORKSPACE($1) and cut the name of the war
WAR=$(find $1 -name *.war | rev | cut -d '/' -f 1 - | rev)
echo "WAR set to $WAR"

# parse $WAR
WAR1=$(echo $WAR | cut -d ' ' -f 1)
PROJECT1=$(echo $WAR1 | cut -d '-' -f 1)
SOURCE1="$1/$PROJECT1/target/$WAR1"
DESTINATION1="search/$PROJECT1/war/recently/$WAR1"

echo "SOURCE1 set to $SOURCE1"
echo "DESTINATION1 set to $DESTINATION1"

WAR2=$(echo $WAR | cut -d ' ' -f 2)
PROJECT2=$(echo $WAR2 | cut -d '-' -f 1)
SOURCE2="$1/$PROJECT2/target/$WAR2"
DESTINATION2="search/$PROJECT2/war/recently/$WAR2"

echo "SOURCE2 set to $SOURCE2"
echo "DESTINATION2 set to $DESTINATION2"

# connect to ftp
ftp -n 192.168.1.254 <<!
        user uploader uploader
        binary
        put $SOURCE1 $DESTINATION1
        put $SOURCE2 $DESTINATION2
        quit
!

exit 0


2. uploadApplicationAutomatically.sh
#!/bin/bash
# Program:
#       This program uploads recent application war to ftp
# History:
#       2011/10/31      Owen.Chen       First Release

# jenkins自动构建前端应用项目成功后,自动在$WORKSPACE中查找对应的应用项目,再解析出上传ftp的source和destination,最后连接ftp上传,这里与搜索项目不同点在于,搜索项目目录下存在2个war需要上传,应用项目目录下只会打一个war等待上传

# find the war of application project in $WORKSPACE($1) and cut the name of the war
WAR=$(find $1 -name *.war | rev | cut -d '/' -f 1 - | rev)
echo "WAR set to $WAR"

PROJECT=$(echo $WAR | cut -d '-' -f 1)
echo "PROJECT set to $PROJECT"

SOURCE="$1/$PROJECT/target/$WAR"
echo "SOURCE set to $SOURCE"

DESTINATION="application/war/$PROJECT/recently/$WAR"
echo "DESTINATION set to $DESTINATION"

ftp -n 192.168.1.254 <<!
        user uploader uploader
        binary
        put $SOURCE $DESTINATION
        quit
!

exit 0


3. jenkins配置
bash /usr/lib/jenkins/script/uploadApplicationAutomatically.sh $WORKSPACE

bash /usr/lib/jenkins/script/uploadSearchAutomatically.sh $WORKSPACE

Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史