- 浏览: 2487454 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Jenkins Configuration(3)Shell Script
Jenkins, we can make SVN, GIT, MAVEN, ANT working on that. But we need to restart JBOSS server, copy the package to working directory, remote access and sync files to other servers. So we need the help from Shell Script.
1. Basic Shell script and basic expect script
Here are the shell script, server-deploy.sh
#!/bin/sh
# copy the file to push directory
STORE_DIST=/android/work_space/push/projectname.war
rm -fr $STORE_DIST;
BUILD_TARGET=war
BUILD_WAR=$(ls $BUILD_TARGET/projectname-*-SNAPSHOT.war)
TMP=${BUILD_WAR%%.war}
unzip -q -d ${TMP} "$BUILD_WAR" ;
cp -r ${TMP} $STORE_DIST;
./server-autopush.exp
We need a exp file to remote access other server, because server-deploy.sh is running on the jenkins build server. We need to sync or rather say push the changes to our testing server, production server. Just note them as some other linux machine, and we need to remotely restart their JBOSS.
#!/usr/bin/expect -f
# December 26 2012
# This script can automatically push the files
# to /opt/jboss-as/server/default/deploy/ on testing server.
# TIMEOUT
set timeout 20
# Login parameters
set server testing.server.com
set port 22
set user deploy
set rootpasswd 111111
# Logfile
log_file server-autopush-run.log
## Enable this and Disable the "spawn ssh ..." above if you are using ssh-key.
#spawn ssh -p $port $user@$server
spawn ssh -p $port -i /home/build/.ssh/id_rsa $user@$server
# Login as Root
expect "*]$\ " {send "su - root\r"}
expect "*assword:\ " {send "$rootpasswd\r"}
# Kill Jboss on testing server
expect "*]#\ " {send "kill -9 \`ps aux | grep /opt/jboss-as/bin/run.jar | grep -v grep | awk \'{print \$2}\'\`\r"}
# Sync the files from testing server to
expect "*]#\ " {send "rsync -arz --delete --force -e \"ssh -i /home/rsync/.ssh/rsync_servers.ppk\" rsync@server.com:/android/work_space/push /opt/build/buildserver/\r"}
# Copy the files from /opt/build/buildserver/push to /opt/jboss-as/server/default/deploy on testing server
expect "*]#\ " {send "\\cp -rpa /opt/build/buildserver/push/* /opt/jboss-as/server/default/deploy/\r"}
# Remove direcotries data,log,work,tmp
expect "*]#\ " {send "\\rm -rf /opt/jboss-as/server/default/tmp\r"}
expect "*]#\ " {send "\\rm -rf /opt/jboss-as/server/default/work\r"}
expect "*]#\ " {send "\\rm -rf /opt/jboss-as/server/default/data\r"}
# Start Jboss on testing server
expect "*]#\ " {send "nohup /etc/init.d/jboss start > /tmp/nohup.out \r"}
# Exit Root
expect "*]#\ " {send "exit\r"}
# Exit User
expect "*]$\ " {send "exit\r"}
# Exit Expect
expect eof
But when I run this method on my server, I got these error messages
Error Message:
>log_file: command not found
>spawn: command not found
>expect: command not found
>expect: command not found
>expect: command not found
>expect: command not found
>expect: command not found
>expect: command not found
That is only because I did not have expect on my machine.
Solution:
>yum update
>yum install tcl
>yum install expect
2. Improvement on SVN checkout process
One import improvement for the workspace working with SVN:
Repository URL: babababababalalalalalaal
Local module directory(optional) This is usually be ./
But I my project is a sub project, so I need some core codes standing there. So I make them svn update to one place
/opt/work_space
/opt/jenkins
So I change the ./ to mostly like this:
./../../../../work_space/branches/development/project/sub_projects/myproject
3. Take some parameters in shell script and expect script
3.1 Shell parameters
I made a test shell file like this test.sh
!/bin/sh
echo There are $# arguments to $0: $*
echo first argument: $1
echo second argument: $2
echo third argument: $3
echo fourth argument: $4
echo here they are again: $@
When I execute it with parameters
>./test.sh 1 2 3 4
There are 4 arguments to ./test.sh: 1 2 3 4
first argument: 1
second argument: 2
third argument: 3
fourth argument: 4
here they are again: 1 2 3 4
3.2 Expect parameters
And example in test.exp working with test.sh
append this line in test.sh
./test.exp h1 h2
test.exp content will be like this>
#!/usr/bin/expect -f
set arg1 [lindex $argv 0]
set arg2 [lindex $argv 1]
send $arg1\n
send $arg2\n
The result will be like this:
>./test.sh 1 2 3 4
There are 4 arguments to ./test.sh: 1 2 3 4
first argument: 1
second argument: 2
third argument: 3
fourth argument: 4
here they are again: 1 2 3 4
h1
h2
4. Some Tips about private/public key
Add one user named deploy
>/usr/sbin/useradd deploy
Give the user an password
>passwd deploy
Generate the key pair
>ssh-keygen -t rsa
Add the public key to authorize
>cd ~/.ssh
>vi authorized_keys
>chmod 711 ~/.ssh
>chmod 644 ~/.ssh/authorized_keys
Client Server tries to login to the remote server
>ssh -i /home/build/.ssh/id_rsa deploy@remote.server.com
Give the rights of directory to one user
>chown -R rsync:rsync /directory/name
rsync is the username, the second rsync is the group name.
Check the public key from private key
>ssh-keygen -f id_rsa -y
references:
http://s3tools.org/s3cmd
http://www.garron.me/mac/install-s3cmd-mac-os-x.html
http://wangyan.org/blog/s3cmd-how-to-use.html
http://osr507doc.sco.com/en/OSUserG/_Passing_to_shell_script.html
Jenkins, we can make SVN, GIT, MAVEN, ANT working on that. But we need to restart JBOSS server, copy the package to working directory, remote access and sync files to other servers. So we need the help from Shell Script.
1. Basic Shell script and basic expect script
Here are the shell script, server-deploy.sh
#!/bin/sh
# copy the file to push directory
STORE_DIST=/android/work_space/push/projectname.war
rm -fr $STORE_DIST;
BUILD_TARGET=war
BUILD_WAR=$(ls $BUILD_TARGET/projectname-*-SNAPSHOT.war)
TMP=${BUILD_WAR%%.war}
unzip -q -d ${TMP} "$BUILD_WAR" ;
cp -r ${TMP} $STORE_DIST;
./server-autopush.exp
We need a exp file to remote access other server, because server-deploy.sh is running on the jenkins build server. We need to sync or rather say push the changes to our testing server, production server. Just note them as some other linux machine, and we need to remotely restart their JBOSS.
#!/usr/bin/expect -f
# December 26 2012
# This script can automatically push the files
# to /opt/jboss-as/server/default/deploy/ on testing server.
# TIMEOUT
set timeout 20
# Login parameters
set server testing.server.com
set port 22
set user deploy
set rootpasswd 111111
# Logfile
log_file server-autopush-run.log
## Enable this and Disable the "spawn ssh ..." above if you are using ssh-key.
#spawn ssh -p $port $user@$server
spawn ssh -p $port -i /home/build/.ssh/id_rsa $user@$server
# Login as Root
expect "*]$\ " {send "su - root\r"}
expect "*assword:\ " {send "$rootpasswd\r"}
# Kill Jboss on testing server
expect "*]#\ " {send "kill -9 \`ps aux | grep /opt/jboss-as/bin/run.jar | grep -v grep | awk \'{print \$2}\'\`\r"}
# Sync the files from testing server to
expect "*]#\ " {send "rsync -arz --delete --force -e \"ssh -i /home/rsync/.ssh/rsync_servers.ppk\" rsync@server.com:/android/work_space/push /opt/build/buildserver/\r"}
# Copy the files from /opt/build/buildserver/push to /opt/jboss-as/server/default/deploy on testing server
expect "*]#\ " {send "\\cp -rpa /opt/build/buildserver/push/* /opt/jboss-as/server/default/deploy/\r"}
# Remove direcotries data,log,work,tmp
expect "*]#\ " {send "\\rm -rf /opt/jboss-as/server/default/tmp\r"}
expect "*]#\ " {send "\\rm -rf /opt/jboss-as/server/default/work\r"}
expect "*]#\ " {send "\\rm -rf /opt/jboss-as/server/default/data\r"}
# Start Jboss on testing server
expect "*]#\ " {send "nohup /etc/init.d/jboss start > /tmp/nohup.out \r"}
# Exit Root
expect "*]#\ " {send "exit\r"}
# Exit User
expect "*]$\ " {send "exit\r"}
# Exit Expect
expect eof
But when I run this method on my server, I got these error messages
Error Message:
>log_file: command not found
>spawn: command not found
>expect: command not found
>expect: command not found
>expect: command not found
>expect: command not found
>expect: command not found
>expect: command not found
That is only because I did not have expect on my machine.
Solution:
>yum update
>yum install tcl
>yum install expect
2. Improvement on SVN checkout process
One import improvement for the workspace working with SVN:
Repository URL: babababababalalalalalaal
Local module directory(optional) This is usually be ./
But I my project is a sub project, so I need some core codes standing there. So I make them svn update to one place
/opt/work_space
/opt/jenkins
So I change the ./ to mostly like this:
./../../../../work_space/branches/development/project/sub_projects/myproject
3. Take some parameters in shell script and expect script
3.1 Shell parameters
I made a test shell file like this test.sh
!/bin/sh
echo There are $# arguments to $0: $*
echo first argument: $1
echo second argument: $2
echo third argument: $3
echo fourth argument: $4
echo here they are again: $@
When I execute it with parameters
>./test.sh 1 2 3 4
There are 4 arguments to ./test.sh: 1 2 3 4
first argument: 1
second argument: 2
third argument: 3
fourth argument: 4
here they are again: 1 2 3 4
3.2 Expect parameters
And example in test.exp working with test.sh
append this line in test.sh
./test.exp h1 h2
test.exp content will be like this>
#!/usr/bin/expect -f
set arg1 [lindex $argv 0]
set arg2 [lindex $argv 1]
send $arg1\n
send $arg2\n
The result will be like this:
>./test.sh 1 2 3 4
There are 4 arguments to ./test.sh: 1 2 3 4
first argument: 1
second argument: 2
third argument: 3
fourth argument: 4
here they are again: 1 2 3 4
h1
h2
4. Some Tips about private/public key
Add one user named deploy
>/usr/sbin/useradd deploy
Give the user an password
>passwd deploy
Generate the key pair
>ssh-keygen -t rsa
Add the public key to authorize
>cd ~/.ssh
>vi authorized_keys
>chmod 711 ~/.ssh
>chmod 644 ~/.ssh/authorized_keys
Client Server tries to login to the remote server
>ssh -i /home/build/.ssh/id_rsa deploy@remote.server.com
Give the rights of directory to one user
>chown -R rsync:rsync /directory/name
rsync is the username, the second rsync is the group name.
Check the public key from private key
>ssh-keygen -f id_rsa -y
references:
http://s3tools.org/s3cmd
http://www.garron.me/mac/install-s3cmd-mac-os-x.html
http://wangyan.org/blog/s3cmd-how-to-use.html
http://osr507doc.sco.com/en/OSUserG/_Passing_to_shell_script.html
发表评论
-
RESTful JSON Mock Server
2015-03-19 11:58 759RESTful JSON Mock Server C ... -
Performance Tool(7)Improve Lua and Wrk
2015-01-17 06:37 1008Performance Tool(7)Improve Lua ... -
Performance Tool(6)Gatling Upgrade to 2.1.2 Version Or wrk
2015-01-10 01:15 938Performance Tool(6)Gatling Upg ... -
Performance Tool(5)Upgrade to 2.0.x
2014-08-27 03:34 1095Performance Tool(5)Upgrade to 2 ... -
Performance Tool(4)CSV File Data Feeder
2014-08-25 10:50 985Performance Tool(4)CSV File Dat ... -
wrk with LuaJIT
2014-08-19 06:30 1298wrk with LuaJITHere is an exa ... -
Performance Tool(3)Gatling Upgrade and Cluster
2014-07-25 02:32 1291Performance Tool(3)Gatling Upgr ... -
WRK a HTTP Benchmarking Tool
2014-03-07 04:42 1101WRK a HTTP Benchmarking Tool1 ... -
Performance Tool(1)Gatling
2013-03-15 05:28 1265Performance Tool(1)Gatling 1. ... -
Jenkins Configuration(4)Improve Shell Script Debug/Info Message
2013-01-07 06:32 1285Jenkins Configuration(4)Improve ... -
Eclipse Plugin(2)SOAP UI
2012-06-08 10:48 1319Eclipse Plugin(2)SOAP UI Plugi ... -
Spring3 and REST Integeration(VII)Controller JUnit Test and Mock/Spring Test MVC
2012-04-06 15:57 1884Spring3 and REST Integeration(V ... -
Spring3 and REST Integration(VI)Controller JUnit Test and Mock/Spring HandlerAda
2012-04-06 15:51 1781Spring3 and REST Integration(VI ... -
Spring3 and REST Integration(V)Controller JUnit Test and Mock/HandlerAdapter
2012-04-06 15:41 2805Spring3 and REST Integration(V) ... -
Spring3 and REST Integration(IV)Controller JUnit Test and Mock/Servlet
2012-04-06 15:13 1908Spring3 and REST Integration(IV ... -
Jbehave(2)Some Improvement and POM changes
2012-03-28 23:11 1399Jbehave(2)Some Improvement and ... -
buildr(1)Introduce and Install
2011-12-23 16:37 2133buildr(1)Introduce and Install ... -
Jbehave(1) First Web Page Sample
2011-10-26 15:00 2166Jbehave(1) First Web Page Sampl ... -
WarcraftIII Problem on English Win7
2011-07-25 10:18 1904WarcraftIII Problem on English ... -
Web Performance Test Tool
2011-05-10 15:37 1401Web Performance Test Tool 1. F ...
相关推荐
Jenkins构建Execute shell script on remote host using ssh命令;JenkinsSSH执行命令;
jenkins 打包 ios shell命令,亲测可用
放在Post Steps 的shell命令 ,一键自动部署(2021最新版)
在Jenkins构建springboot项目自动部署的时候,配置远程执行Dockerfile所在服务器的SSH命令,这里把完整的命令贴出来,详细搭建过程见我的博客《基于Jenkins+Gitlab+Docker实现SpringBoot项目自动部署》
Jenkins自动部署Shell脚本分享(注意,仅用于Shell脚本分享,因环境不同,不可用于其它环境自动部署使用) #!/bin/bash #时间:2019年7月29日 #作者:肖山 #微信:helpxiaoshan #用途:用于 XXXX UAT环境ATG商城项目...
干货:Jenkins Pipeline调用shell、python、java、groovy脚本的正确使用姿势.doc
jenkins-backup-script, 归档jenkins设置和插件 Jenkins备份脚本 归档Jenkins设置和插件$JENKINS_HOME/*.xml$JENKINS_HOME/jobs/*/*.xml$JENKINS_HOME/nodes/*$JENKINS_HOME/plugi
NULL 博文链接:https://jiuyuehe.iteye.com/blog/1843103
shell脚本自动化运行job,运维,测试,开发作持续集成
迁移jenkins时,需要依赖windows的节点,在网上查了资料装好以后,接下来简直就是噩梦,因为没有人指导,在...如果在job里使用了 Execute shell 在windows服务器上执行的会提示没有找到此命令,等类似的错误,这个
Jenkins+Git+Maven+Shell+Tomcat持续集成环境 Jenkins+Git+Maven+Shell+Tomcat持续集成环境
Jenkins+SVN+MAVEN+SHELL实现项目一键发布,非常好的学习资料
包含NodePort,HostPort,ClusterIp几种方式自动化部署脚本。
詹金斯配置Groovy脚本集合,用于自动配置Jenkins和第三方插件诸如Jenkins Job DSL之类的工具允许您以编程方式创建作业和其他资源。 但是,Jenkins本身的配置仍然是手动过程,容易出错。 这些脚本可用于创建可重现...
Linux Shell Script with Bash , it is target for advanced user. it is useful
Jenkins插件:Post-Build Script Plug-in 最稳定的版本
第 3章 Jenkins – Tomcat Setup 7 第4章 Jenkins – Git Setup 9 第 5章 Jenkins – Maven Setup 12 第6章 Jenkins – Configuration 16 第7章 Jenkins – Management 18 第 8 章 Jenkins – 设置Build Job 21 第 9...
使用Jenkins搭建自动构建平台,自动打包AndroidStudio工程,使用Gradle构建。代码来源git