Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-72716

credentialsId shows different in `Jenkins.instance.nodes` and `Jenkins.instance.computers`

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Critical Critical
    • core, ssh-slaves-plugin

      I've been updated credential ID in the SSH Agent ( hudson.plugins.sshslaves.SSHLauncher ), when I using script to check the credentialsId status, find out the jenkins.model.Jenkins.instance.nodes works as I saw in configure page, however, the jenkins.model.Jenkins.instance.computers still shows the legacy ( previous ) credentialsId .

       

      groovy script for list nodes credentials:

      computer.getNode():

      Jenkins.instance.computers.findAll { computer ->
        ! jenkins.model.Jenkins.MasterComputer.isInstance(computer) &&
        computer?.launcher instanceof hudson.plugins.sshslaves.SSHLauncher
      }.each { computer ->
        println computer.node.launcher?.credentialsId?.toString()     // shows updated, same with configuration page
        println computer.launcher?.credentialsId?.toString()          // issue: shows the legacy credentialsId
      }
      

       
      node.toComputer():

      Jenkins.instance.nodes.findAll { node ->
        ! jenkins.model.Jenkins.MasterComputer.isInstance(node) &&
        node?.launcher instanceof hudson.plugins.sshslaves.SSHLauncher
      }.each { node ->
        println node.launcher?.credentialsId?.toString() + ' : ' + node.getClass()
        println node.toComputer().launcher?.credentialsId?.toString() + ' : ' + node.toComputer().getClass()
      }
      

      screenshot:

      BTW, here is the groovy script to update nodes credential:

      import jenkins.model.Jenkins
      import hudson.plugins.sshslaves.SSHLauncher
      import hudson.slaves.ComputerLauncher
      
      String newCredId = 'GIT_SSH_CREDENTIAL'
      
      Jenkins.instance.nodes.findAll { node ->
        ! jenkins.model.Jenkins.MasterComputer.isInstance(node) &&
        node?.launcher instanceof hudson.plugins.sshslaves.SSHLauncher
      }.each { node ->
        ComputerLauncher launcher = node.launcher
        SSHLauncher newLauncher = new SSHLauncher( launcher.host, launcher.port, newCredId )
        node.setLauncher( newLauncher )
        node.save()
        println ">> ${node.name} DONE <<"
      }
      

            Unassigned Unassigned
            marslo Marslo Jiao
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: