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

NullPointerException when using Credentials Binding Plugin

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Labels:
      None
    • Environment:
      Jenkins server: runs on jenkins/jenkins:lts docker image (image id: 5907903170ad), with Jenkins version 2.150.1.
      Credentials-binding-plugin version: 1.17.
      Agent: runs on the server node.
    • Similar Issues:

      Description

      A NullPointerException with no stacktrace is experienced when trying to run the following pipeline:

      pipeline {
          agent any
          stages {
              stage('stage usernameColonPassword') {
                  steps {
                      sh 'echo usernameColonPassword 1'
                      withCredentials([usernameColonPassword(credentialsId: 'mysecret', variable: 'SECRET')]) {
                          sh 'echo usernameColonPassword 2' 
                      }
                  }
              }
              stage('stage usernamePassword') {
                  steps {
                      sh 'echo usernamePassword 3'
                      withCredentials([usernamePassword(credentialsId: 'mysecret', passwordVariable: 'SECRET2')]) {
                          sh 'echo usernamePassword 4' 
                      }
                  }
              }
          }
      }
      
      

      where "mysecret" is a credential with it's "kind" being "username and password".

      This exception causes the job to fail.

       

      Specifically, `usernameColonPassword` succeeds, while `usernamePassword` fails; `usernamePassword 4` is never printed to the log.

       

      This was the first time I have tried to run this script, so I have never observed this succeeding; for all I know, it has always failed.

       

      My workaround options are bad:  either parse the password out of the `user:pass` format, or abandon the plugin.

       

      UPDATE: as mentioned in the comments, there is a better workaround.  This ticket is now for removing or documenting the requirement for all arguments to be used, and creating a useful error message.

        Attachments

          Activity

          Hide
          cowlinator p cowlinator added a comment -

          I have found a resolution for this issue.

          By including the "usernameVariable" argument, the null reference exception goes away:

          withCredentials([usernamePassword(credentialsId: 'mysecret', passwordVariable: 'SECRET2', usernameVariable: 'USELESS')]) {
          

          Please no longer require arguments that may not be useful to the user; or, document that all arguments are required and print a more helpful error when they are not provided.

          Show
          cowlinator p cowlinator added a comment - I have found a resolution for this issue. By including the "usernameVariable" argument, the null reference exception goes away: withCredentials([usernamePassword(credentialsId: 'mysecret' , passwordVariable: 'SECRET2' , usernameVariable: 'USELESS' )]) { Please no longer require arguments that may not be useful to the user; or, document that all arguments are required and print a more helpful error when they are not provided.
          Hide
          tony_k tony kerz added a comment -

          thanks p cowlinator you are the man!

          i burned a few hours on this until i came across your post!

          i'll have to second the vote to not crash hard when one of the args isn't passed

          Show
          tony_k tony kerz added a comment - thanks p cowlinator you are the man! i burned a few hours on this until i came across your post! i'll have to second the vote to not crash hard when one of the args isn't passed

            People

            • Assignee:
              Unassigned
              Reporter:
              cowlinator p cowlinator
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: