How to use configure block in DSL to execute shell script on remote host using ssh

950 views
Skip to first unread message

xia...@gmail.com

unread,
Jan 10, 2014, 3:40:09 AM1/10/14
to job-dsl...@googlegroups.com
I recently started to use  job-dsl-plugin. I can use it to create simple job.
But if I require the job to invoke ssh script on remote host via SSH plugin, how I can implement it via configure block in job dsl? If configure block can not implement it, is there other ways?

The following is my expected job, which is generated via jenkins' UI.
<builders>
<org.jvnet.hudson.plugins.SSHBuilder plugin="ssh@2.3">
<siteName>ro...@9.123.333.444:22</siteName>
<command>echo 'just for test'</command>
</org.jvnet.hudson.plugins.SSHBuilder>
</builders> 

I write the following dsl script. It execute successfully, but nothing happen, no job was created. 
When I remove the configure block, the job "myjob" can be created.

job{
   name("myjob")
   description ("description of myjob")
   configure { project ->
      def sshNode =  project/builders/"org.jvnet.hudson.plugins.SSHBuilder plugin='ssh@2.3'"
      sshNode/siteName("ro...@9.123.333.444:22")
      sshNode/command( "echo 'just for test'")
   }
}

Thanks your help.

Justin Ryan

unread,
Jan 19, 2014, 3:34:33 AM1/19/14
to job-dsl-plugin
The syntax for the plugin attribute is wrong. If you were to look at
the resulting config.xml you'd some some weird xml, e.g.
<org.jvnet.hudson.plugins.SSHBuilder plugin='ssh@2.3'>
<siteName>ro...@9.123.333.444:22</siteName>
<command>echo 'just for test'</command>
</org.jvnet.hudson.plugins.SSHBuilder plugin='ssh@2.3>

The easiest thing is to remove the plugin reference and try this:

configure { project ->
def sshNode = project/builders/"org.jvnet.hudson.plugins.SSHBuilder"
sshNode/siteName("ro...@9.123.333.444:22")
sshNode/command( "echo 'just for test'")
}

> --
> You received this message because you are subscribed to the Google Groups
> "job-dsl-plugin" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to job-dsl-plugi...@googlegroups.com.
> To post to this group, send email to job-dsl...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/job-dsl-plugin/920ac4bc-5722-44c4-9bc3-4d1acf565fd8%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages