Docker Jenkins Blue Ocean can not run ssh scp in Pipeline Docker Jenkins Blue Ocean can not run ssh scp in Pipeline jenkins jenkins

Docker Jenkins Blue Ocean can not run ssh scp in Pipeline


For me the key to understanding was that the Build-Executor named "Master" is the runtime "Agent" context for the blueocean jenkinsci FROM jenkinsci/blueocean image

In the Jenkinsfile saying agent { label 'master' } means run steps on Master, agent { label 'Dockerfile' } means run steps in the projects docker container.

You need a multi agent pipeline, so start with agent none and add an agent in each stage targeting its agent enviroment. in this case agent { label 'master' } to run ssh from the jenkinsci/blueocean container

Too obvious for anyone to explain ... !

You'll need the SSH Agent Plugin to create a credential, and copy in a private ssh key. It will give you an ID to use in your Jenkinsfile DSL script

pipeline {  agent none  stages {    stage('Hello Docker') {      agent { dockerfile {filename 'Dockerfile'}}      steps {        echo 'Hello Docker'      }    } stage('Make useful SSH connections') {        agent { label 'master' }        steps{             //Your in the in Master Container             sh 'hostname'             //In this working directory             sh 'pwd'             //You provide SSH credentails via the SSHagent              sshagent(credentials : ['<ID OF THE SSH AGENT CREDENTIAL>']) {             //Connect to hostip/s with ssh, run scripts, go wild!             sh 'ssh -o StrictHostKeyChecking=no user@hostip uptime'             //and SCP              sh 'scp ./source/filename user@hostip:/remotehost/target             }      }}

Jenkins nodes are controlled by the agent label, cool :)