我已经在单独的ec2服务器中构建了代码,并生成了.tar文件,我需要使用Jenkins通过ssh发布工件将其发送到单独的服务器。
shell命令位于以下位置: 构建命令
ls -dt /opt/LCMA-ui/*-feature1.tar | tail -n +3 | xargs rm -rf
npm install
bower install
grunt build
cp .tmp/app/app.css client/app/
ln -sf /opt/LCMA-ui/ /var/lib/jenkins/workspace/LCMA-feature1/LCMA-feature1-tar
tar -cf /opt/LCMA-ui/${VERSION}.${BUILD_NUMBER}-feature1.tar client/ server/ node_modules/ package.json config.json bower.json .bowerrc
源文件: ** / LCMA-feature1-tar / $ {VERSION}。$ {BUILD_NUMBER} -feature1.tar
发布构建命令
cd /opt/lcma/
mkdir ${VERSION}.${BUILD_NUMBER}-feature1
tar -xC ${VERSION}.${BUILD_NUMBER}-feature1/ -f ./LCMA-feature1-tar/${VERSION}.${BUILD_NUMBER}-feature1.tar
rm feature1
ln -sf /opt/lcma/${VERSION}.${BUILD_NUMBER}-feature1/ /opt/lcma/feature1
cd /opt/lcma/feature1
mv client/ public
rm /opt/lcma/${VERSION}.${BUILD_NUMBER}-feature1/public/assets/css/lyt1-theme-2.css
cd ../
rm ./LCMA-feature1-tar/${VERSION}.${BUILD_NUMBER}-feature1.tar
ls -dt /opt/lcma/*-feature1/ | tail -n +4 | xargs rm -rf
pm2 restart ui-feature1
Tar文件是在Building ec2服务器中生成的,但是未复制到另一个发布服务器。我已经检查了全局SSH凭据并进行了测试,并且显示还可以。
控制台输出为
21:20:35 + tar -cf /opt/LCMA-ui/1.8.0.85-feature1.tar client/ server/ node_modules/ package.json config.json bower.json .bowerrc
21:22:57 SSH: Connecting from host [ip-10-xx-0-xx]
21:22:57 SSH: Connecting with configuration [Web-server] ...
21:22:57 SSH: Creating session: username [jenkins], hostname [ec2-34-225-xxx-xxx.compute-1.amazonaws.com], port [22]
21:22:57 SSH: Connecting session ...
21:22:58 SSH: Connected
21:22:58 SSH: Opening SFTP channel ...
21:22:58 SSH: SFTP channel open
21:22:58 SSH: Connecting SFTP channel ...
21:23:03 SSH: Connected
21:23:03 SSH: cd [/opt/lcma]
21:23:03 SSH: OK
21:23:09 SSH: Opening exec channel ...
21:23:09 SSH: EXEC: channel open
21:23:09 SSH: EXEC: STDOUT/STDERR from command [cd /opt/lcma/
21:23:09 mkdir 1.8.0.85-feature1
21:23:09 tar -xC 1.8.0.85-feature1/ -f ./LCMA-feature1-tar/1.8.0.85-feature1.tar
21:23:09 rm feature1
21:23:09 ln -sf /opt/lcma/1.8.0.85-feature1/ /opt/lcma/feature1
21:23:09 cd /opt/lcma/feature1
21:23:09 mv client/ public
21:23:09 rm /opt/lcma/1.8.0.85-feature1/public/assets/css/lyt1-theme-2.css
21:23:09 cd ../
21:23:09 rm ./LCMA-feature1-tar/1.8.0.85-feature1.tar
21:23:09 ls -dt /opt/lcma/*-feature1/ | tail -n +4 | xargs rm -rf
21:23:09 pm2 restart ui-feature1] ...
21:23:09 SSH: EXEC: connected
21:23:10 tar: ./LCMA-feature1-tar/1.8.0.85-feature1.tar: Cannot open: No such file or directory
21:23:10 tar: Error is not recoverable: exiting now
21:23:10 mv: cannot stat 'client/': No such file or directory
21:23:10 rm: cannot remove '/opt/lcma/1.8.0.85-feature1/public/assets/css/lyt1-theme-2.css': No such file or directory
21:23:10 rm: cannot remove './LCMA-feature1-tar/1.8.0.85-feature1.tar': No such file or directory
21:23:26 Use --update-env to update environment variables
21:23:27 [PM2] Applying action restartProcessId on app [ui-feature1](ids: 3)
21:23:28 [PM2] [ui-feature1](3) ✓
21:23:29 ┌─────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬─────────┬──────────┐
21:23:29 │ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
21:23:29 ├─────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼─────────┼──────────┤
21:23:29 │ qa │ 0 │ fork │ 26298 │ online │ 22235 │ 21s │ 20% │ 44.9 MB │ jenkins │ disabled │
21:23:29 │ ui-feature1 │ 3 │ fork │ 26373 │ online │ 40599 │ 0s │ 19% │ 11.6 MB │ jenkins │ disabled │
21:23:29 │ ui-feature2 │ 4 │ fork │ 21791 │ online │ 0 │ 2D │ 0% │ 86.6 MB │ jenkins │ disabled │
21:23:29 │ ui-gms │ 5 │ fork │ 21797 │ online │ 0 │ 2D │ 0% │ 75.9 MB │ jenkins │ disabled │
21:23:29 │ ui-qa │ 1 │ fork │ 18570 │ online │ 16886 │ 30h │ 0% │ 90.9 MB │ jenkins │ disabled │
21:23:29 │ ui-uat │ 2 │ fork │ 21779 │ online │ 0 │ 2D │ 0% │ 76.3 MB │ jenkins │ disabled │
21:23:29 └─────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴─────────┴──────────┘
21:23:29 Use `pm2 show <id|name>` to get more details about an app
21:23:29 SSH: EXEC: completed after 19,887 ms
21:23:29 SSH: Disconnecting configuration [Web-server] ...
21:23:29 SSH: Transferred 0 file(s)
21:23:29 Finished: SUCCESS