[英]How to run pipeline from Jenkins to another adress
我有一個任務是在 Jenkins 上創建一個管道,它在 docker 上進行 pull 和 up -d compose 在另一個工作區,另一個服務器上。 只有 Jenkins 在 172.16.0.x 上,我必須在另一台服務器 172.16.0.x 上運行此管道。 我聽說要更改 POST 所在的 header '-URL'。 你能幫我嗎我可以改變它或者我怎么能解決這個問題? 我正在尋找但找不到任何東西。 :( 我的管道: pipeline { agent any stages{ stage('Update_docker'){ steps{ bat "docker-compose pull" bat "docker-compose up -d" } } } }
當我在本地主機上運行該 pinepline 時,一切都會成功。
為了在不同的服務器上執行命令,您需要先連接到它。 例如,您可以 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"......
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"
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.