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

Should be able to bind credentials to groovy without requiring a node.

XMLWordPrintable

      create a credential of type secretText.

      Attempt to use it in a workflow like

      withCredentials([[$class: 'StringBinding', credentialsId: 'production_magic', variable: 'magicValue']]) {
          while (true) {
            def theguess= input id: 'guess', message: 'Please enter the magic value', parameters: [[$class: 'com.michelin.cio.hudson.plugins.passwordparam.PasswordParameterDefinition', name: 'Your guess']]
            if (magicValue != theguess) {
              echo "you guessed wrong!"
            }
            else {
                break
            }
          }
          echo "Congrats you guessed correctly!"
      }
      

      This is not currently possible and to access the credential you need to read it from the environment

      e.g.

      withCredentials([[$class: 'StringBinding', credentialsId: 'production_magic', variable: 'magicValue']]) {
          while (true) {
            def theguess= input id: 'guess', message: 'Please enter the magic value', parameters: [[$class: 'com.michelin.cio.hudson.plugins.passwordparam.PasswordParameterDefinition', name: 'Your guess']]
            if (env.magicValue != theguess) {
              echo "you guessed wrong!"
            }
            else {
                break
            }
          }
          echo "Congrats you guessed correctly!"
      }
      

      however - this does not work as the environment requires a node context!

      So there should be a way to bind credentials (that make sense) to groovy without requiring a node as requiring a node can take resources and will be locked for the duration until whatever needs the credential is done (and if that is an input you lock an executor).

      Current workaround for not locking executors is to get the variable in a block and assign it to another variable.
      THis has the consequence that the variable exists outside of the scope of withcredentials - and it may be persisted somewhere.

            jglick Jesse Glick
            teilo James Nord
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: