首页 > 解决方案 > 在没有从站的远程主机上执行 Jenkins 管道

问题描述

我的 Jenkins 在 host1 上,我希望使用 Jenkins 管道触发 host2 上的 ansible。这可以通过在 host2 上创建一个从节点并agent在 Jenkins 管道中指定来完成。

但是,我在 host2 上没有 Jenkins 从站。

相反,Jenkins 可以连接到 host2,通过Server Groups Center它可以在下面找到Jenkins Global Configuration

我需要在 host2 上安装一个 Jenkins 从站吗?如果没有,那么我如何Server Groups Center在 Jenkins 管道中使用来触发 host2 上的 Ansible?请提供示例代码...</p>

标签: jenkinstriggersansiblejenkins-pipelineremote-server

解决方案


我需要在 host2 上安装 Jenkins 从站吗?

不,如果你有 Linux host2:你可以简单地通过 SSH 运行任何命令。

如何使用 Jenkins 管道中的服务器组中心在 host2 上触发 Ansible?

Server Groups Centerblock 来自SSH2 Easy 插件,它很老,不支持Jenkins 管道。因此,您不能在管道中使用来自该设置块的信息。

但是还有其他的 SSH 插件;例如,尝试通过 SSH插件发布。该插件将Publish over SSH块添加到Jenkins Global Configuration,您可以在其中指定host2连接参数。

然后您可以编写如下管道步骤(是您在块中键入{HOST2}的名称):host2Publish over SSHJenkins Global Configuration

steps {
    sshPublisher \
        failOnError: true, \
        publishers: [ \
            sshPublisherDesc( \
                configName: "{HOST2}", \
                transfers: [ \
                    sshTransfer (execCommand: "ansible -m ping all -i inventory_file", execTimeout: 120000) \
                ] \
            ) \
        ]
}

推荐阅读