---
title: "【Jenkins Pipeline】Distributed builds"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/jenkins-pipeline-distributed-builds/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/03-软件工程与质量保障/CI-CD与质量保障/CI-CD工具链/【Jenkins Pipeline】Distributed builds.md"
content_hash: fbe41b318d1187ff004ac1335d30d1e8b941b864a603164296eaa3edafa6cac9
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# 【Jenkins Pipeline】Distributed builds

> 创建时间：2021/7/13 12:25

  * 【Jenkins Pipeline】Distributed builds
    * Terms
      * Agent与双向连接
    * 连接方式区别与选择
      *         * Master to agent connections [ SSH ]
        * Agent to master connections [ JNLP ]
        * 其他
    * 设置项
      * Usage
      * 其他小的设置项
    * 实践总结
      * Windows
        * JavaWS
        * SSH
      * MacOS
        * JavaWS
        * SSH Username & Password
        * SSH Private Key
    * Ref

## Terms

Jenkins 官方wiki：<https://wiki.jenkins.io/display/jenkins/distributed+builds>

### Agent与双向连接

An agent is a computer that is set up to offload build projects from the master and once setup this distribution of tasks is fairly automatic.

There are various ways to start agents, but in the end the agent and Jenkins master need to establish a bi-directional communication link (for example a TCP/IP socket) in order to operate.

A server that runs an agent is often referred to as a “Node” in Jenkins terminology.

## 连接方式区别与选择

本质区别是：initiated from the master vs. from the agent end

#### Master to agent connections [ SSH ]

适用情况：Unix agents
This is the most convenient and preferred method for **Unix agents** , which normally has sshd out-of-the-box.

网络权限条件：This does require that the master have network access (ingress) to the agent (typically this is via ssh).

关键步骤：the agent will need the master’s public ssh key copied to ~/.ssh/authorized_keys.
a decent howto ：<http://www.linuxproblem.org/art_9.html>

#### Agent to master connections [ JNLP ]

适用情况：

网络权限条件：
In some cases this is not desirable due to security network rules, in which case you can use Agent to master connections via “JNLP”.
the agent server will not be visible to the master.
the agents are behind a firewall
the master does not need network “ingress” to the agent (but the agent will need to be able to connect back to the master).

关键步骤：
manage Jenkins->Global Security->TCP port for JNLP agents
需要把 Jenkins URL 设置为 <http://[ip_server]:8080/>

#### 其他

Master to agent connections ：

  * Write your own script to launch Jenkins agents

  * remote management facility built into Windows 2000 or later

## 设置项

### Usage

  * Utilize this node as much as possible - Jenkins may run any job on the slave as long as it is available.
这个节点上的Executor都可以作为候选的Executor，如果一个Job的Node设置为Any，则会自动选择在哪个节点上执行。如果子节点的Usage为Utilize this node as much as possible，那么会优先在子节点上执行。子节点的Executor都用完，就会在其他”Utilize this node as much as possible”的节点上运行。

  * “Leave this node for tied jobs only” - Jenkins will only build a project (or job) on this node when that project specifically was tied to that node.This allows a slave to be reserved for certain kinds of jobs.
只有指定了node为该节点，才会在该节点上执行。

一般不同的机器会要求执行不同的任务，不同的节点的环境也会不一样，所以一般使用第二种方式即可。

### 其他小的设置项

Use WebSocket - 尚不明确

> WebSocket是一种网络传输协议，可在单个TCP连接上进行全双工通信，位于OSI模型的应用层。

## 实践总结

### Windows

#### JavaWS

环境要求：Java8环境

方法（步骤）：

![Alt text](/media/2aea6f6835adc218fd3a.png)

环境变量加载情况：
双击运行，与系统设置中的用户变量及系统变量一致。
CMD运行，与CMD程序的环境变量一致。

SVN是否需要密码：不需要，密码会在Subversion目录当中，加密的方案是windows-cryptoapi。

#### SSH

理论上可以实现，但是很麻烦，不建议折腾。

### MacOS

#### JavaWS

环境要求：
Java8

方法（步骤）：

* * *

环境变量加载情况：

如果终端启动，则环境变量会从该shell程序继承。

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

如果通过点击slave-node.jnlp文件的方式启动，则

* * *

SVN是否需要密码：

#### SSH Username & Password

环境要求：
防火墙无所谓
system preferences -> sharing -> enable remote login

方法（步骤）：

环境变量加载情况：
不会自动加载用户或系统的profile文件。可用Prefix Start Agent Command 来加载环境变量。
在Jenkins服务器上设置得子节点的环境变量只有在启动后才会生效。

SVN是否需要密码：
需要，除非明文保存密码，或每次都解锁Keychain。

#### SSH Private Key

环境要求：the agent will need the master’s public ssh key copied to ~/.ssh/authorized_keys.

方法（步骤）：

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

Credentials中添加证书，配置生成的私钥即可。

环境变量加载情况：与用户名密码登陆的方式相同，不会自动加在环境变量。

SVN是否需要密码：SSH Username & Password

## Ref

<https://wiki.jenkins.io/display/jenkins/distributed+builds>
