标签:line += url 认证 pac 项目 inf 后端服务 red
#以上构建的pipeline脚本:
node("node1"){
stage("clone code"){
sh ‘rm -rf /var/lib/jenkins/workspace/pipeline-job/*‘
git branch: ‘develop‘, credentialsId: ‘1f60339e-fbb3-41e6-88a7-ae80834823b4‘, url: ‘git@192.168.1.30:jie/web-page.git‘
}
stage("compress code"){
sh ‘cd /var/lib/jenkins/workspace/pipeline-job/ && tar cvf index_code.tar.gz *‘
}
stage("send code"){
sh ‘ssh 192.168.1.23 "/usr/sbin/nginx -s stop"‘
sh ‘ssh 192.168.1.23 "rm -rf /apps/nginx/html/*"‘
sh ‘scp /var/lib/jenkins/workspace/pipeline-job/index_code.tar.gz 192.168.1.23:/apps/nginx/html‘
}
stage("deploy code"){
sh ‘ssh 192.168.1.23 "cd /apps/nginx/html/ && tar xvf index_code.tar.gz"‘
sh ‘ssh 192.168.1.23 "/usr/sbin/nginx"‘
}
}
[root@node1 workspace]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:YHTsZqXXSRMoV2ZG3gEgGYEzxdHEF4kNYlIc75Qy6JI root@node1
The key‘s randomart image is:
+---[RSA 2048]----+
| oB%X+OX=. |
| .+=*+B**. . |
| ++o=++.o. |
| + .==. o |
| E .oS.. |
| . |
| |
| |
| |
+----[SHA256]-----+
[root@node1 ~]# ssh-copy-id 192.168.1.23
root@node1 ~]# ll /var/lib/jenkins/workspace/pipeline-job
total 16
-rw-r--r-- 1 root root 10240 Jul 26 16:42 index_code.tar.gz
-rw-r--r-- 1 root root 42 Jul 26 16:42 index.html
jenkins的pipeline实现指定节点项目构建并部署代码至后端服务器
标签:line += url 认证 pac 项目 inf 后端服务 red
原文地址:https://blog.51cto.com/14234542/2423949