OLS
OLS

Reputation: 325

How to conver NODE to STAGE in jenkins

I need to run commands over server using SSH. I found this [https://github.com/jenkinsci/ssh-steps-plugin][plugin] that does it nicely. but it's written as a node, and not as pipeline step.

node {
  def remote = [:]
  remote.name = 'test'
  remote.host = 'test.domain.com'
  remote.user = 'root'
  remote.password = 'password'
  remote.allowAnyHosts = true
  stage('Remote SSH') {
    sshRemove remote: remote, path: "abc.sh"
  }
}

How can I transform it to pipeline {} stage?

Upvotes: 0

Views: 83

Answers (1)

Kiruba
Kiruba

Reputation: 1377

It is straight forward you can simply move above remote steps into stage. I used to do like below. (I have used private key for ssh authentication)

steps {
        script {
            def remote = [:]
            withCredentials([
                sshUserPrivateKey(credentialsId: 'PRIVATE_KEY_FILE', keyFileVariable: 'identityFile', passphraseVariable: 'passphrase', usernameVariable: 'userName')
            ]) {
            remote.name = "test.host.com"
            remote.host = "10.0.0.1"
            remote.allowAnyHosts = true
            remote.user = userName
            remote.identityFile = identityFile
            remote.passphrase = passphrase
            sshScript remote: remote, script: "runTestScript.sh"
        }
    }
}

Please refer https://github.com/jenkinsci/ssh-steps-plugin#pipeline-steps

Upvotes: 1

Related Questions