[JIRA] (JENKINS-57269) Declarative pipeline with ssh-steps-plugin

947 views
Skip to first unread message

dfranco@dflc.ch (JIRA)

unread,
May 1, 2019, 3:35:03 AM5/1/19
to jenkinsc...@googlegroups.com
Davide F created an issue
 
Jenkins / Bug JENKINS-57269
Declarative pipeline with ssh-steps-plugin
Issue Type: Bug Bug
Assignee: Naresh Rayapati
Components: ssh-steps-plugin
Created: 2019-05-01 07:34
Environment: Jenkins (version 2.150.2)
ssh steps plugin (version 1.2.1)
Priority: Minor Minor
Reporter: Davide F

Hello,

This is a question more than a bug report.

I'd like to use ssh private key account (with passphrase) from Jenkins credentials store.

I did successfully used this plugin with an ssh key pair in a scripted pipeline using the provided code sample below

https://github.com/jenkinsci/ssh-steps-plugin#withcredentials

My groovy code looks like this

def remote = [:]
remote.name = "hostname"
remote.host = "hostname"
remote.allowAnyHosts = true
node {
  withCredentials([sshUserPrivateKey(credentialsId: 'xxxxx-xxxxx-xxxx', keyFileVariable: 'identity', passphraseVariable: 'passphrase', usernameVariable: 'userName')]) {
  remote.user = userName
    remote.identityFile = identity
  remote.passphrase = passphrase
  stage("SSH Steps Rocks!") {
    writeFile file: 'abc.sh', text: 'ls'
    sshPut remote: remote, from: 'abc.sh', into: '.'
  }
}

I've tried in several way to use Declarative Pipeline but without success.

Do you have any tips or samples to share ?

Thanks for your help.

Davide

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

naresh.rayapati@gmail.com (JIRA)

unread,
May 1, 2019, 11:43:03 AM5/1/19
to jenkinsc...@googlegroups.com
Naresh Rayapati commented on Bug JENKINS-57269
 
Re: Declarative pipeline with ssh-steps-plugin

Can you post your declarative pipeline snippets also please?

The Declarative model for Jenkins Pipelines has a restricted subset of syntax that it allows in the stage blocks - see the syntax guide for more info. You can bypass that restriction by wrapping your steps in a script { ... } block.

dfranco@dflc.ch (JIRA)

unread,
May 2, 2019, 3:25:02 AM5/2/19
to jenkinsc...@googlegroups.com
Davide F commented on Bug JENKINS-57269

Hello Naresh Rayapati,

Thanks for your quick feedback.

Here's how I've tried to use script block in a declarative pipeline

pipeline {
  agent any
    stages {
      stage ('Main Stage') {
        steps {
          script {
            stage ('nothing but display a message') {
              echo 'First stage'
{{            }}}
            stage ('ssh') {


              def remote = [:]
              remote.name = "hostname"

              remote.host = "fqdn-hostname"
              remote.port = custom-port
              remote.allowAnyHosts = true
              withCredentials([sshUserPrivateKey(credentialsId: 'xxxxxxxx', keyFileVariable: 'key', passphraseVariable: 'passphrase', usernameVariable: 'username')]) {
              remote.passphrase = passphrase
              sshGet(remote: remote, from: 'abc.sh', into: 'abc.sh', override: true)
{{           }}}
{{         }}}
{{       }}}
{{     }}}
{{   }}}
 }
}

The job is "stuck" at sshGet step and I have to terminate the step manually to get the job finish.

But if I use the example below (using sshagent), the job works just fine.

pipeline {
  agent any
    stages {
      stage ('Main Stage') {
        steps {
          script {
            stage ('nothing but display a message') {
              echo 'First stage'
{{            }}}
            stage ('ssh') {
              withCredentials([sshUserPrivateKey(credentialsId: '}}{{xxxxxxxxxxxxx}}{{',   keyFileVariable: 'key', passphraseVariable: 'passphrase', usernameVariable: 'username')]) {
{{ remote.passphrase = passphrase}}
                sshagent(['xxxxxxxxxxxxx']) {
   sh 'scp -o StrictHostKeyChecking=no $username@hostname:~/abc.sh .'
{{              }}}
{{            }}}
{{          }}}
{{        }}}
{{      }}}
{{    }}}
{{  }}}
}

Any idea ?

Thanks for your help

Davide

dfranco@dflc.ch (JIRA)

unread,
May 2, 2019, 3:27:02 AM5/2/19
to jenkinsc...@googlegroups.com
Davide F edited a comment on Bug JENKINS-57269
Hello [~nrayapati],

dfranco@dflc.ch (JIRA)

unread,
May 10, 2019, 8:20:02 AM5/10/19
to jenkinsc...@googlegroups.com
Davide F commented on Bug JENKINS-57269

Hello,

Do you have any update regarding this support request ?

Best regards

Davide

naresh.rayapati@gmail.com (JIRA)

unread,
May 30, 2019, 12:00:02 PM5/30/19
to jenkinsc...@googlegroups.com

As mentioned before please use script block to execute these steps within declarative pipelines.

naresh.rayapati@gmail.com (JIRA)

unread,
May 30, 2019, 12:03:03 PM5/30/19
to jenkinsc...@googlegroups.com
Naresh Rayapati edited a comment on Bug JENKINS-57269
As mentioned before please use script block to execute these steps within declarative pipelines.


And in the above code, it isn't setting the credentials to the remote: please follow the documentation on the readme for more information. https://github.com/jenkinsci/ssh-steps-plugin#configuration

username
identityFile

naresh.rayapati@gmail.com (JIRA)

unread,
Jun 9, 2019, 4:19:03 PM6/9/19
to jenkinsc...@googlegroups.com

Davide F Closing this Jira for now, please don't mind to reopen or log another Jira in case if you need more help. Thank you. 

naresh.rayapati@gmail.com (JIRA)

unread,
Jun 9, 2019, 4:19:03 PM6/9/19
to jenkinsc...@googlegroups.com
Naresh Rayapati closed an issue as Not A Defect
Change By: Naresh Rayapati
Status: Open Closed
Resolution: Not A Defect

luckyhk.lee@samsung.com (JIRA)

unread,
Dec 12, 2019, 3:39:03 AM12/12/19
to jenkinsc...@googlegroups.com

Naresh Rayapati

Hello.

Please provide syntax for declarative pipeline.

I don't want to use 'script' anymore.

 

Thanks.

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

boyang.song2046@gmail.com (JIRA)

unread,
Apr 19, 2020, 4:55:03 PM4/19/20
to jenkinsc...@googlegroups.com

I am new to Jenkins.

 

Now the trend is the declarative pipeline. I find difficult to learn (groovy) scripted pipeline and the hybrid style with 'script{}' in the declarative pipeline.

 

Would you provide an example declarative pipeline using ssh-steps-plugin?

 

Thank you

This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages