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

Provide some mechanism for looking up whether credentials exist in Pipeline

    Details

    • Similar Issues:

      Description

      In my use-case, I need to use the same Jenkinsfile on multiple Jenkins instances. The only differentiation between the two are the credentials which are available for use. (Basically, one instance is authorized for deployments, thus the credentials, the other is not).

      My ideal would be a credentials global variable, or something like that, which could have utility methods like this. E.g.

      node {
        if (credentials.lookup('some-credentials-id')) {
          withCredentials('some-credentials-id') {
            sh './deploy.sh'
          }
        }
      }
      

      Related to JENKINS-37863

        Attachments

          Issue Links

            Activity

            Hide
            jglick Jesse Glick added a comment -

            I suppose you could say, for example

            boolean stringCredentialsExist(String id) {
              try {
                withCredentials([string(credentialsId: id, variable: 'irrelevant')]) {
                  true
                }
              } catch (_) {
                false
              }
            }
            
            Show
            jglick Jesse Glick added a comment - I suppose you could say, for example boolean stringCredentialsExist( String id) { try { withCredentials([string(credentialsId: id, variable: 'irrelevant' )]) { true } } catch (_) { false } }
            Hide
            pietervogelaar Pieter Vogelaar added a comment -

            Jesse Glick Thanks, that example worked great!

            Show
            pietervogelaar Pieter Vogelaar added a comment - Jesse Glick Thanks, that example worked great!

              People

              • Assignee:
                Unassigned
                Reporter:
                rtyler R. Tyler Croy
              • Votes:
                3 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: