gitjenkinsgithubcontinuous-integrationjenkins-github-plugin

Where can i get / generate git project's credentialsId to be used in jenkins?


I am trying to checkout my code base using jenkins pipeline. To do that i need 'credentialsId' for authentication purpose.

 stage('Checkout my codebase') {
     steps {
         dir('terraform_src') {
             git(
                 branch: "${GIT_BRANCH}",
                 credentialsId: "${GIT_CREDENTIALS}",
                 url: "git@bitbucket.org:org_name/project_name.git",
             )
         }

     }
 }

How can i generate or where can i get the value for 'credentialsId' string?

Currently in my local machine i am using user name and password for authentication purposes for pull and push.

How to create 'credentialsId' using my user name and password?


Solution

  • Login to your jenkins machine.

    1. Click Manage jenkins from the side menu bar in jenkins.
    2. Scroll down and you will find 'Manage Credentials' option with description 'Configure credentials.'. Click on the 'Manage Credentials' option.

    manage_credentials

    1. Under 'Stores scoped to Jenkins' section, click on 'Jenkins' hyper-link.

    stores

    1. In 'System' section, click Global credentials (unrestricted) . global_section

    2. In the next screen, you will see 2 options in the sidebar,

    1. Click 'Add Credentials' and it will open up form. Select 'Kind', 'scope' and fill the username and password. id field can be left blank since this will be generated by jenkins if left blank. Provide valid description to the key which will be helpful for identifying the key and it's purpose later.

    add_data

    1. Go to Global credentials page again and you will see the new entry is listed in the table. You can copy the id from the table

    Got some inputs from the StackOverflow answer and corresponding comments.