I got a task to create a pipeline on Jenkins which make a pull and up -d on docker compose on another workspace, another server. Just Jenkins is on 172.16.0.x and i have to run this pipeline on another server 172.16.0.x. I heard something about change the header '-URL' where POST is going. Can u help me guys where i can change it or how i can solve that ? I'm looking for and can't find anything. :(
My pipeline:
pipeline { agent any stages{ stage('Update_docker'){ steps{ bat "docker-compose pull" bat "docker-compose up -d" } } } }
When i running that pinepline on localhost everything going success.
CodePudding user response:
In order to execute commands on a different server, you need to first connect to it. For example, you can SSH into the remote machine and execute the commands there. You can use something like SSH Step for this.
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"
}
Another option is to add the remote server as a Jenkins agent and execute the command on the remote Agent. For this you can change the agent directive pipeline { agent {label: "server2" ......
CodePudding user response:
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"
}
}
}
}