Jenkins自动发布(4)-新建节点执行远程命令

1 系统管理--管理节点

2  远程服务器信息 

   IP:192.168.1.106   

   java:jdk1.8
    
   java_home:/usr/local/jdk1.8.0_181
   
   user:root
   
   user_pwd: 123456

3  新建节点

远程工作目录:/root/.jenkins

启动方式:Launch slave agents via ssh

主机:远程服务器IP

Credentials: 配置远程服务器用户名和密码

Java 路径:远程服务器jdk目录/bin/java

Jenkins自动发布(4)-新建节点执行远程命令_第1张图片

完成以上配置保存即可

4 节点信息

Jenkins自动发布(4)-新建节点执行远程命令_第2张图片

5 连接节点

点击 jenkinsWeb,显示下图,然后点击启动代理连接远程服务器

Jenkins自动发布(4)-新建节点执行远程命令_第3张图片

6 连接成功信息

[09/01/18 17:00:30] [SSH] Opening SSH connection to 192.168.1.106:22.
[09/01/18 17:00:30] [SSH] SSH host key matches key in Known Hosts file. Connection will be allowed.
[09/01/18 17:00:30] [SSH] 认证成功。

.....................省略部分内容................................

[09/01/18 17:00:30] [SSH] Starting sftp client.
[09/01/18 17:00:30] [SSH] 正在拷贝最新版本的 slave.jar...
[09/01/18 17:00:30] [SSH] Copied 771,004 bytes.
Expanded the channel window size to 4MB
[09/01/18 17:00:30] [SSH] Starting slave process: cd "/root/.jenkins" && /usr/local/jdk1.8.0_181/bin/java  -jar slave.jar
<===[JENKINS REMOTING CAPACITY]===>channel started
Remoting version: 3.21
这是一个Unix代理
Evacuated stdout
Agent successfully connected and online

7  连接成功

Jenkins自动发布(4)-新建节点执行远程命令_第4张图片

8  新建Task

Jenkins自动发布(4)-新建节点执行远程命令_第5张图片

9 配置任务 General

选中  限制项目的运行节点(此任务只能在此服务器执行),标签表达式输入 节点名称

Jenkins自动发布(4)-新建节点执行远程命令_第6张图片

10 配置任务 构建

选择执行shell

Jenkins自动发布(4)-新建节点执行远程命令_第7张图片

录入shell命令

Jenkins自动发布(4)-新建节点执行远程命令_第8张图片

保存即可!

11 执行任务

点击 立即构建,下面会出现构建进度

Jenkins自动发布(4)-新建节点执行远程命令_第9张图片

12 任务结果

点击  #1 ,显示下图,然后点击 控制台输出,查看远程shell执行结果

Jenkins自动发布(4)-新建节点执行远程命令_第10张图片

执行结果信息

由用户 admin 启动
在远程节点 jenkinsWeb 上构建 在工作空间 /root/.jenkins/workspace/远程执行命令测试 中
[远程执行命令测试] $ /bin/sh -xe /tmp/jenkins7238737686296656874.sh
+ ifconfig
ens33: flags=4163  mtu 1500
        inet 192.168.1.106  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe62:2a2b  prefixlen 64  scopeid 0x20
        ether 00:0c:29:62:2a:2b  txqueuelen 1000  (Ethernet)
        RX packets 16028  bytes 13030812 (12.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7237  bytes 7450878 (7.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 0  (Local Loopback)
        RX packets 4  bytes 340 (340.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 340 (340.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:51:c7:6c  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

+ ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:62:2a:2b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.106/24 brd 192.168.1.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe62:2a2b/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0:  mtu 1500 qdisc noqueue state DOWN 
    link/ether 52:54:00:51:c7:6c brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic:  mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:51:c7:6c brd ff:ff:ff:ff:ff:ff
Finished: SUCCESS

 

你可能感兴趣的:(自动发布)