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

how to use perforce credential in pipeline

    Details

    • Similar Issues:

      Description

      Hi,

       

      Is it possible to use perforce password credential in pipeline?

       

      like,

      withCredentials([ usernamePassword(
        credentialsId: 'perforce',
        usernameVariable: 'P4_USER',
        passwordVariable: 'P4_PASSWORD')
      ]) {
        ...
      }

      If not provided, please add this feature.

       

      Thanks,

        Attachments

          Activity

          Hide
          p4karl Karl Wirth added a comment -

          Hi Hokwang Lee. No I dont think that is possible. What is the usage case? For example do you have may Jenkins Masters and this would cut down on local configuration?

          Show
          p4karl Karl Wirth added a comment - Hi Hokwang Lee . No I dont think that is possible. What is the usage case? For example do you have may Jenkins Masters and this would cut down on local configuration?
          Hide
          p4karl Karl Wirth added a comment -

          Hello Hokwang Lee - Did you see my last message? Can you please provide an example of how you would use this.

          In my testing the 'withCredentials' seems to be used to access the Perforce password already stored in the credential 'perforce' (from your example). For me this works and I can access the password in the variable 'P4_PASSWORD' from within my Jenkinsfile.

          Show
          p4karl Karl Wirth added a comment - Hello Hokwang Lee - Did you see my last message? Can you please provide an example of how you would use this. In my testing the 'withCredentials' seems to be used to access the Perforce password already stored in the credential 'perforce' (from your example). For me this works and I can access the password in the variable 'P4_PASSWORD' from within my Jenkinsfile.
          Hide
          luckyhorang Hokwang Lee added a comment -

          Hi, Karl Wirth

          I've tested.

           

          1) When I create "Username with password" kind in Jenkins Credentials page,

          I can use this in below format. There's no problem.

          withCredentials([ usernamePassword(
          

          2) I just ask that can I use "Perforce Password Credential" kind or not.

          Like

          withCredentials([ perforcePassword(
          

          Now I should create both "Username with password" and "Perforce Password Credential".

          Show
          luckyhorang Hokwang Lee added a comment - Hi, Karl Wirth I've tested.   1) When I create "Username with password" kind in Jenkins Credentials page, I can use this in below format. There's no problem. withCredentials([ usernamePassword( 2) I just ask that can I use "Perforce Password Credential" kind or not. Like withCredentials([ perforcePassword( Now I should create both "Username with password" and "Perforce Password Credential".
          Hide
          p4karl Karl Wirth added a comment -

          Hello Hokwang Lee - I will correct my original response and say yes it is possoble. As you have found  'usernamePassword' gets the correct information:

          node {
           withCredentials([usernamePassword(credentialsId: 'MyJenkinsP4Credential', usernameVariable: 'USERNAME', passwordVariable: 'PASS')]) {
              sh '''
                set +x
                echo "User is $USERNAME " > out.txt
                echo "Pass is $PASS" >> out.txt
              '''
            }
          }
          

          Important note: If you try to echo the variables or 'out.txt' to job console in Jenkins you will see the user and password replaced with the text '****' . However the contents on disk does contain my credentials:

          $ cat /var/lib/jenkins/workspace/JENKINS-58209-withCredetials/out.txt
          User is jenkinsuser 
          Pass is Password123
          

          Is there any reason why you need a 'perforcePassword' and how would it differ from usernamePassword?

           

           

           

           

           

          Show
          p4karl Karl Wirth added a comment - Hello Hokwang Lee - I will correct my original response and say yes it is possoble. As you have found  'usernamePassword' gets the correct information: node { withCredentials([usernamePassword(credentialsId: 'MyJenkinsP4Credential' , usernameVariable: 'USERNAME' , passwordVariable: 'PASS' )]) { sh ''' set +x echo "User is $USERNAME " > out.txt echo "Pass is $PASS" >> out.txt ''' } } Important note: If you try to echo the variables or 'out.txt' to job console in Jenkins you will see the user and password replaced with the text '****' . However the contents on disk does contain my credentials: $ cat / var /lib/jenkins/workspace/JENKINS-58209-withCredetials/out.txt User is jenkinsuser Pass is Password123 Is there any reason why you need a 'perforcePassword' and how would it differ from usernamePassword?          
          Hide
          luckyhorang Hokwang Lee added a comment -

          Karl,

           

          Thanks, I checked, there's no problem.

          You can close this issue.

          Show
          luckyhorang Hokwang Lee added a comment - Karl,   Thanks, I checked, there's no problem. You can close this issue.
          Hide
          p4karl Karl Wirth added a comment -

          Hi Hokwang Lee. Thanks.

          Show
          p4karl Karl Wirth added a comment - Hi Hokwang Lee . Thanks.
          Hide
          p4karl Karl Wirth added a comment -

          Yes the Perforce credentials are accessible using 'withCredentials'.

          Show
          p4karl Karl Wirth added a comment - Yes the Perforce credentials are accessible using 'withCredentials'.

            People

            • Assignee:
              p4karl Karl Wirth
              Reporter:
              luckyhorang Hokwang Lee
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: