Using ssh-agent with jenkins while polling SCM Using ssh-agent with jenkins while polling SCM jenkins jenkins

Using ssh-agent with jenkins while polling SCM


Removing the passphrase from the SSH key is an unacceptable step.

The jenkins ssh-agent plugin is expected to solve this problem, but as far as I can tell it's currently broken where polling is concerned:

https://issues.jenkins-ci.org/browse/JENKINS-21226

I have not found a viable, secure means to implement ssh-based server communication that also covers polling, as of Jenkins 1.545.


Assume that your Jobs running on Jenkins master.To be able to do polling for Git repo which require SSL connection:

  1. Backup your private key.
  2. Remove passphrase from your private key using that one solution: How do I remove the passphrase for the SSH key without having to create a new key?
  3. Add password-less private key on to your Jenkins server into Jenkins's home dir + .ssh subfolder f.e. for CEntOS it is in /var/lib/jenkins/.ssh. Make sure that only jenkins user can access that key (use chmod 600, and chown jenkins:jenkins for that).
  4. In Jenkins's Credential Manager add new SSH key with username and specify full location for just configured private key f.e. /var/lib/jenkins/.ssh/id_rsa
  5. Setup your Job and specify those credentials for Git repo settings and SSH agent plugin.

After those steps you are able to do polling to trigger Job when necessary as well as cloning and fetching from Job itself.


EDIT: While the below solution apparently works for the commenter on that JIRA issue, it doesn't for me. Your mileage may vary.

From your job's Configuration page, under Additional Behaviours, add "Force polling using workspace"

Seems to have been available since September 2014.

via https://issues.jenkins-ci.org/browse/JENKINS-21226?focusedCommentId=210643&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-210643