Add credentials in pipeline script

58 views
Skip to first unread message

Onno van der Straaten

unread,
Apr 20, 2016, 7:05:57 AM4/20/16
to Jenkins Users
Hi,
I changed the example pipeline script a bit to test if it would work using Subversion. The repository that I want to use does not allow anonymous access. Is it possible to add credentials?
Cheers,
Onno

node {
   // Mark the code checkout 'stage'....
   stage 'Checkout'

   // Get some code from a GitHub repository
   svn url: 'https://mysvnurl

   // Get the maven tool.
   // ** NOTE: This 'M3' maven tool must be configured
   // **       in the global configuration.           
   def mvnHome = tool 'Maven 3.2.5'

   // Mark the code build 'stage'....
   stage 'Build'
   // Run the maven build
   sh "${mvnHome}/bin/mvn clean install"
}

Alex Domoradov

unread,
Apr 20, 2016, 10:23:53 AM4/20/16
to Jenkins Users
You could try something like this

node {
  withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'mylogin',
                    usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
    sh '''
      set +x
      curl -u $USERNAME:$PASSWORD https://private.server/ > output
    '''
  }
}

https://www.cloudbees.com/blog/workflow-integration-credentials-binding-plugin

Reply all
Reply to author
Forward
0 new messages