2
votes

I am trying to test each step by step for creating a Jenkins pipeline job. For that, I am trying to test with svn checkout first for my sample pipeline. And I added declarative pipeline and added the svn checkout step. But I am getting the error like following:

svn: E215004: No more credentials or we tried too many times.

And I added my pipeline job like the following:

pipeline 
  {
    agent any
    stages 
      {
        stage ('Checkout') 
         {                 
           steps
             {
                sh 'svn co http://192.168.16.174/repository/pipeline'
             }
         }
     }
  }

My observation

According to my observation, I did not added the svn repository credentials here. I am new to Jenkins and CI/CD. When I learning I saw that we can create credentials in Jenkins and can refer that ID here. But I did not got exactly how to add. Also another thing is that, I planned to add this in a Jenkinsfile which is storing in repository root directory.

My confusion

  1. If I am referring the created credentials here , how i can refer?
  2. If I am keeping my Jenkinsfile in my project root directory to pull, Is there any problem if I am adding the credentials ID inside my Jenkinsfile?

I have here lot of confusions related with credentials inside Jenkinsfile. Please correct me if I went in wrong direction.

1

1 Answers

1
votes

After little bit exploration I found that , Need to use the "withCredentials" option from jenkins to bind the created credentials to a uername and password variable. After binding in the stage steps , need to use the username and password variable with the SVN repository URL that we are going to hit using 'sh' command. Let me add what I did here ,

pipeline 
{
    agent any
    stages 
        {
            stage ('Checkout') 
                {
                    steps
                        {

            withCredentials([[$class: 'UsernamePasswordMultiBinding',
                  credentialsId: '<credential-ID>',
                  usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
    sh "svn co url --username $USERNAME --password $PASSWORD"
                                     }

                        }
                }
        }

}

And will get the output like the following in the console like the following form,

Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node (hide)
Running on Jenkins in /var/lib/jenkins/workspace/kubernetes
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] withCredentials
Masking only exact matches of $USERNAME or $PASSWORD
[Pipeline] {
[Pipeline] sh
+ svn co 'url' --username **** --password ****
Checked out revision 1.
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS