
// Configure global ssh credentials
def ssh_credentials = { instance, id, username, privateKeyFile, description, passphrase='' ->
  // Retrieve the Global credential store
  def domain = com.cloudbees.plugins.credentials.domains.Domain.global()
  def store = instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()

  def privateKeySource = new com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.FileOnMasterPrivateKeySource(privateKeyFile)

  // Create the SSH credential
  def my_creds = new com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey(
    com.cloudbees.plugins.credentials.CredentialsScope.GLOBAL,
    id,
    username,
    privateKeySource,
    passphrase,
    description
  )
  store.addCredentials(domain, my_creds)
}

