1

I have a jenkins pipeline in groovy. One of the jobs is to upload the artifact to artifactory. I used variables to use curl as showed in picture and it works fine, but I don´t know how to hide user and pass on jenkins output job. I don´t know much about groovy, is this possible?

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

2

1 Answer 1

6

You can use Credentials Binding Plugin along with Credentials Plugin.

Credentials will be available as an env variable, but will be masked if you try to print it out.

Exmaple

withCredentials([usernamePassword(credentialsId: 'amazon', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
  sh 'curl -u $USERNAME:$PASSWORD http://localhost:8080'
}
8
  • I will try , but can this be used from a curl comand as I´m using? curl -u user:pass ?
    – Chanafot
    Apr 6, 2018 at 23:39
  • Yes. Check the updated example.
    – yausername
    Apr 6, 2018 at 23:50
  • I understand the " withCredentials([usernamePassword(credentialsId:" an so on, but where should I place this? in my groovy code under "node { ?" chek my image. I believe the example you are saying is for a regular pipeline for jenkins but not using groovy.
    – Chanafot
    Apr 7, 2018 at 14:39
  • Just wrapping your curl command in withCredentials should work. Or you can check this
    – yausername
    Apr 7, 2018 at 15:47
  • I have modified as you suggest and it makes sense, but I´m getting this error (check 2 new images) . I´m quite lost now. those plug in are already installed on kenkins pipeline. org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: artifactory
    – Chanafot
    Apr 9, 2018 at 15:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.