`
42087743
  • 浏览: 237070 次
  • 性别: Icon_minigender_1
  • 来自: 合肥&上海
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics