How do I initiate a puppet run from Jenkins?

96 views
Skip to first unread message

lfast

unread,
May 10, 2015, 2:10:45 AM5/10/15
to jenkins...@googlegroups.com
I'm getting lost in the number of different ways to integration Jenkins & Puppet.  What I'm looking for should be simple:  From Jenkins, execute puppet agent/apply on a remote server. 

I'm currently using the SSH plugin to run puppet on the remote server.  I'm just starting to look at the Workflow system but as yet haven't found the syntax for using the SSH plugin in a Workflow or anything equivalent.

I also recognize that the core issue here is managing authentication onto the remote server.  Are there any 'best practices' for this?  General recommendations or even 'this worked for me' would also make me happy.

lfast

unread,
May 10, 2015, 11:38:36 AM5/10/15
to jenkins...@googlegroups.com
I tried the following:
node {
 step([$class: 'org.jvnet.hudson.plugins.SSHBuilder',
       siteName: 'me@myserver:22',
       command: 'echo hello myserver|tee testJenkins'
      ])
}
But if I'm guessing right, this plugin requires an update to be compatible with Workflow.  Here's the error I get.

java.lang.ClassCastException: class org.jvnet.hudson.plugins.SSHBuilder
	at java.lang.Class.asSubclass(Class.java:3037)
	at org.jenkinsci.plugins.workflow.structs.DescribableHelper.coerce(DescribableHelper.java:183)
        ...
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
	at WorkflowScript.run(WorkflowScript:2)


Yasir Saleem

unread,
May 20, 2015, 2:32:56 PM5/20/15
to jenkins...@googlegroups.com
You can use something like this:

This mechanism help you do any ssh related task. Where 'ssh_key_file' is secrete file base credentials.


def runShellwithCredentials(ssh_key_file,cmd) {
  env.RUN_CMD = cmd
  try {
    withCredentials([[$class: 'FileBinding', variable: 'PVT_KEY_FILE', credentialsId: ssh_key_file]]) {
      sh '''
chmod 0500 $PVT_KEY_FILE
env
eval `ssh-agent`
ssh-add $PVT_KEY_FILE
$RUN_CMD
kill -s term $SSH_AGENT_PID
'''
    }
  } catch (e) {
    def w = e.printStackTrace()
    mailSubject += " has failed with ${e.message}"
    mailBody += mailSubject
    mailer(mailSubject,mailBody)
    throw e
  }
}

Wei Chen

unread,
Oct 26, 2015, 3:12:16 AM10/26/15
to Jenkins Users
Hi,

Is your code Java-Code? Why using Java in puppet?

Wei Chen

unread,
Oct 26, 2015, 3:12:50 AM10/26/15
to Jenkins Users
Hi,

I have the similar question as yours. Have you got the solutiuon?

Wei
Reply all
Reply to author
Forward
0 new messages