【问题标题】:How to run pipeline from Jenkins to another adress如何从 Jenkins 运行管道到另一个地址
【发布时间】:2023-01-17 17:29:05
【问题描述】:
我有一个任务是在 Jenkins 上创建一个管道,它在另一个工作区、另一个服务器上对 docker compose 进行 pull 和 up -d。只有 Jenkins 在 172.16.0.x 上,我必须在另一台服务器 172.16.0.x 上运行这个管道。我听说要更改 POST 所在的标头“-URL”。你们能帮助我吗我可以改变它或我如何解决它?我正在寻找但找不到任何东西。 :(
我的管道:
pipeline { agent any stages{ stage('Update_docker'){ steps{ bat "docker-compose pull" bat "docker-compose up -d" } } } }
当我在本地主机上运行该 pinepline 时,一切都会成功。
【问题讨论】:
标签:
jenkins
jenkins-pipeline
pipeline
【解决方案1】:
为了在不同的服务器上执行命令,您需要先连接到它。例如,您可以通过 SSH 连接到远程机器并在那里执行命令。您可以为此使用SSH Step之类的东西。
def remote = [:]
remote.name = 'test'
remote.host = 'test.domain.com'
remote.user = 'root'
remote.password = 'password'
remote.allowAnyHosts = true
stage('Remote SSH') {
sshCommand remote: remote, command: "docker-compose up -d"
}
另一种选择是将远程服务器添加为 Jenkins 代理并在远程代理上执行命令。为此,您可以更改代理指令pipeline { agent {label: "server2" ......
【解决方案2】:
pipeline {
agent any
stages{
stage('Update_docker'){
step{
def remote = [:]
remote.name = 'server2'
remote.host = '172.16.x.x:9001'
remote.user = 'ci'
remote.password = 'xxxxxxx'
remote.allowAnyHosts = true
stage('Remote SSH') {
sshCommand remote: remote, command: "docker-compose up -d"
}
}
}
}