• Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • p4-plugin

      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,

          [JENKINS-58209] how to use perforce credential in pipeline

          Karl Wirth added a comment -

          Hi luckyhorang. 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?

          Karl Wirth added a comment - Hi luckyhorang . 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?

          Karl Wirth added a comment -

          Hello luckyhorang - 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.

          Karl Wirth added a comment - Hello luckyhorang - 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.

          Hokwang Lee added a comment -

          Hi, p4karl

          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".

          Hokwang Lee added a comment - Hi, p4karl 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".

          Karl Wirth added a comment -

          Hello luckyhorang - 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?

           

           

           

           

           

          Karl Wirth added a comment - Hello luckyhorang - 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?          

          Hokwang Lee added a comment -

          Karl,

           

          Thanks, I checked, there's no problem.

          You can close this issue.

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

          Karl Wirth added a comment -

          Hi luckyhorang. Thanks.

          Karl Wirth added a comment - Hi luckyhorang . Thanks.

          Karl Wirth added a comment -

          Yes the Perforce credentials are accessible using 'withCredentials'.

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

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

              Created:
              Updated:
              Resolved: