- 浏览: 2551178 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 800RESTful JSON Mock Server C ... -
Performance Tool(7)Improve Lua and Wrk
2015-01-17 06:37 1036Performance Tool(7)Improve Lua ... -
Performance Tool(6)Gatling Upgrade to 2.1.2 Version Or wrk
2015-01-10 01:15 979Performance Tool(6)Gatling Upg ... -
Performance Tool(5)Upgrade to 2.0.x
2014-08-27 03:34 1127Performance Tool(5)Upgrade to 2 ... -
Performance Tool(4)CSV File Data Feeder
2014-08-25 10:50 1031Performance Tool(4)CSV File Dat ... -
wrk with LuaJIT
2014-08-19 06:30 1335wrk with LuaJITHere is an exa ... -
Performance Tool(3)Gatling Upgrade and Cluster
2014-07-25 02:32 1335Performance Tool(3)Gatling Upgr ... -
WRK a HTTP Benchmarking Tool
2014-03-07 04:42 1144WRK a HTTP Benchmarking Tool1 ... -
Performance Tool(1)Gatling
2013-03-15 05:28 1294Performance Tool(1)Gatling 1. ... -
Jenkins Configuration(4)Improve Shell Script Debug/Info Message
2013-01-07 06:32 1338Jenkins Configuration(4)Improve ... -
Eclipse Plugin(2)SOAP UI
2012-06-08 10:48 1352Eclipse Plugin(2)SOAP UI Plugi ... -
Spring3 and REST Integeration(VII)Controller JUnit Test and Mock/Spring Test MVC
2012-04-06 15:57 1911Spring3 and REST Integeration(V ... -
Spring3 and REST Integration(VI)Controller JUnit Test and Mock/Spring HandlerAda
2012-04-06 15:51 1821Spring3 and REST Integration(VI ... -
Spring3 and REST Integration(V)Controller JUnit Test and Mock/HandlerAdapter
2012-04-06 15:41 2839Spring3 and REST Integration(V) ... -
Spring3 and REST Integration(IV)Controller JUnit Test and Mock/Servlet
2012-04-06 15:13 1989Spring3 and REST Integration(IV ... -
Jbehave(2)Some Improvement and POM changes
2012-03-28 23:11 1428Jbehave(2)Some Improvement and ... -
buildr(1)Introduce and Install
2011-12-23 16:37 2189buildr(1)Introduce and Install ... -
Jbehave(1) First Web Page Sample
2011-10-26 15:00 2205Jbehave(1) First Web Page Sampl ... -
WarcraftIII Problem on English Win7
2011-07-25 10:18 1946WarcraftIII Problem on English ... -
Web Performance Test Tool
2011-05-10 15:37 1458Web Performance Test Tool 1. F ...
相关推荐
Jenkins构建Execute shell script on remote host using ssh命令;JenkinsSSH执行命令;
在Jenkins构建springboot项目自动部署的时候,配置远程执行Dockerfile所在服务器的SSH命令,这里把完整的命令贴出来,详细搭建过程见我的博客《基于Jenkins+Gitlab+Docker实现SpringBoot项目自动部署》
放在Post Steps 的shell命令 ,一键自动部署(2021最新版)
### Jenkins 打包 iOS 使用 Shell 命令详解 #### 一、背景介绍 在持续集成(CI)的流程中,使用自动化工具如Jenkins来构建iOS应用是常见且高效的做法。通过Shell脚本实现自动化的打包过程可以极大提高开发效率,并...
3. **与Jenkins结合**:在Jenkins中,可以通过SHELL脚本来执行构建前后的自定义任务,如代码格式检查、环境变量设置等。 4. **在持续集成中的作用**:SHELL脚本可以用来自动化部署过程,例如打包、发布、启动服务等...
Jenkins Pipeline 调用 shell、python、java、groovy 脚本的正确使用姿势 Jenkins Pipeline 是一个强大的自动化工具,可以帮助开发者自动化构建、测试和部署流程。在设计 Pipeline 脚本的过程中,经常会遇到调用...
Jenkins自动部署Shell脚本分享(注意,仅用于Shell脚本分享,因环境不同,不可用于其它环境自动部署使用) #!/bin/bash #时间:2019年7月29日 #作者:肖山 #微信:helpxiaoshan #用途:用于 XXXX UAT环境ATG商城项目...
- 在 Windows 版本的 Jenkins 中使用 shell 命令,需先下载 curl 工具 - 示例:上传 release 版本至第三方平台 ```bash cd ../../../curl curl -F "file=@../jobs/AndroidBuildRelease/workspace/app/build/...
jenkins-backup-script, 归档jenkins设置和插件 Jenkins备份脚本 归档Jenkins设置和插件$JENKINS_HOME/*.xml$JENKINS_HOME/jobs/*/*.xml$JENKINS_HOME/nodes/*$JENKINS_HOME/plugi
9. **持续集成/持续部署(CI/CD)**:在现代软件开发流程中,shell脚本常用于CI/CD工具(如Jenkins、GitLab CI/CD),自动执行构建、测试和部署任务。 总的来说,"shell_script.zip"提供的这些脚本是实现自动化任务的...
jdk1.8支持的最后一个版本jenkins,验证可用Jenkins Jenkins 2.289.3 jenkins.msi jdk1.8支持的最后一个版本jenkins,验证可用Jenkins Jenkins 2.289.3 jenkins.msi jdk1.8支持的最后一个版本jenkins,验证可用...
1. **脚本语言选择**:Post-Build Script Plug-in支持多种脚本语言,包括Unix Shell(bash、sh)、Windows批处理(cmd、bat)和Groovy。选择合适的语言编写符合项目需求的脚本。 2. **脚本内容**:脚本可以执行任何...
Jenkins 2.387.3 是一个高度可扩展的持续集成和持续部署(CI/CD)工具,广泛应用于IT行业的自动化部署流程。这个版本是专为Windows操作系统设计的安装包,旨在帮助开发者和运维人员更便捷地在Windows环境中设置和...
Jenkins+Git+Maven+Shell+Tomcat 持续集成环境 本文主要讲述如何使用 Jenkins、Git、Maven、Shell 和 Tomcat 搭建一个持续集成环境,以提高软件开发效率和质量。首先,Jenkins 是一个开源软件项目,旨在提供一个...
shell脚本自动化运行job,运维,测试,开发作持续集成
整个过程可以分为四个步骤:安装 Docker、安装 Jenkins、配置 Jenkins 基本信息、使用 Dockerfile 和 shell 脚本实现项目自动拉取打包并运行。 安装 Docker 首先,需要安装 Docker 社区版本 CE。确保 yum 包更新到...
3. 添加Shell脚本:在构建步骤中添加Shell命令,执行部署相关的操作,比如将打包后的应用复制到远程服务器,或者执行数据库迁移。 4. 配置部署环境:确保远程服务器上已安装好必要的环境(如Java运行时、服务器软件...
迁移jenkins时,需要依赖windows的节点,在网上查了资料装好以后,接下来简直就是噩梦,因为没有人指导,在...如果在job里使用了 Execute shell 在windows服务器上执行的会提示没有找到此命令,等类似的错误,这个