Spawning container an remote docker host works when we are using agent labels/templates and a jenkins freestyle project as you have shown in many tutorials. But when we are going to a multibranch pipeline project, there seems no way to execute any command in the newly spawned (independed) remote container.
Does anyone has any experience using multibranch pipeline jobs with scripted jenkinsfile? We don't want to use these jenkins agent labels, because we have great number of different images for our build jobs. It would be really tedious to configure 'every' day new docker templates using jenkins gui. We like our developer-teams to edit the image name in the jenkinsfile and commit it to the project repository.
When trying to use a scripted jenkinsfile like these little PoC it always happens, that a new container is spawned, but the three 'sh' commands are executed within the jenkins-master container instead of the newly spawned container.
node {
docker.withServer('tcp://192.168.122.1:4243') {
docker.image('bash:latest').withRun() {
sh 'hostname -I'
sh 'sleep 60s'
sh 'hostname -I'
}
}
}
Any help apreciated.