在没有从站的情况下在远程主机上执行 Jenkins 管道
Execute a Jenkins pipeline on remote host without a slave
我的 Jenkins 在 host1 上,我希望使用 Jenkins 管道触发 host2 上的 ansible。这可以通过在 host2 上创建一个从节点并在 Jenkins 管道中指定 agent
来完成。
但是,我在 host2 上没有 Jenkins slave。
相反,Jenkins 通过 Server Groups Center
连接到主机 2,可以在 Jenkins Global Configuration
下找到
我需要 host2 上的 Jenkins slave 吗?如果没有,那么我如何在 Jenkins 管道中使用 Server Groups Center
来触发 host2 上的 Ansible?请示例代码...
Do I need a Jenkins slave on host2?
不,如果您在 host2
上有 Linux:您可以简单地 运行 通过 SSH 的任何命令。
How can I use Server Groups Center in Jenkins pipeline to trigger Ansible on host2?
Server Groups Center
块来自 SSH2 Easy plugin, which is very old and doesn't support Jenkins 管道。因此,您不能在管道中使用来自该设置块的信息。
但是还有其他的 SSH 插件;例如尝试 Publish over SSH 插件。此插件将 Publish over SSH
块添加到 Jenkins Global Configuration
,您可以在其中指定 host2
连接参数。
然后你可以写管道步骤如下({HOST2}
是你在Jenkins Global Configuration
中的Publish over SSH
块中键入的host2
的名称):
steps {
sshPublisher \
failOnError: true, \
publishers: [ \
sshPublisherDesc( \
configName: "{HOST2}", \
transfers: [ \
sshTransfer (execCommand: "ansible -m ping all -i inventory_file", execTimeout: 120000) \
] \
) \
]
}
我的 Jenkins 在 host1 上,我希望使用 Jenkins 管道触发 host2 上的 ansible。这可以通过在 host2 上创建一个从节点并在 Jenkins 管道中指定 agent
来完成。
但是,我在 host2 上没有 Jenkins slave。
相反,Jenkins 通过 Server Groups Center
连接到主机 2,可以在 Jenkins Global Configuration
我需要 host2 上的 Jenkins slave 吗?如果没有,那么我如何在 Jenkins 管道中使用 Server Groups Center
来触发 host2 上的 Ansible?请示例代码...
Do I need a Jenkins slave on host2?
不,如果您在 host2
上有 Linux:您可以简单地 运行 通过 SSH 的任何命令。
How can I use Server Groups Center in Jenkins pipeline to trigger Ansible on host2?
Server Groups Center
块来自 SSH2 Easy plugin, which is very old and doesn't support Jenkins 管道。因此,您不能在管道中使用来自该设置块的信息。
但是还有其他的 SSH 插件;例如尝试 Publish over SSH 插件。此插件将 Publish over SSH
块添加到 Jenkins Global Configuration
,您可以在其中指定 host2
连接参数。
然后你可以写管道步骤如下({HOST2}
是你在Jenkins Global Configuration
中的Publish over SSH
块中键入的host2
的名称):
steps {
sshPublisher \
failOnError: true, \
publishers: [ \
sshPublisherDesc( \
configName: "{HOST2}", \
transfers: [ \
sshTransfer (execCommand: "ansible -m ping all -i inventory_file", execTimeout: 120000) \
] \
) \
]
}