-
Story
-
Resolution: Fixed
-
Minor
-
None
I have a jenkins pipeline from SCM running in jenkins with a groovyscript. In one of the steps I have upload a file to artifactory with CURL - u user:pass , but don´t wan´t that user and pass be visible in output of pipeline in jenkins. I have read in several places the "Withcredential" function but I´m not quite sure how to this works or apply or implement. I tried this 2 options with no luck:
stage ('Upload war to Artifactory') { withCredentials([usernamePassword(credentialsId: 'artifactory', usernameVariable: username', passwordVariable: 'password')])
sh "sudo curl -u $username:$password -T $warPath 'https://artifactory.xxx.com:443/artifactory/form/$warFile'" }
In this case I´m getting:
org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: artifactory at org.jenkinsci.plugins.credentialsbinding.MultiBinding.getCredentials(MultiBinding.java:153) at org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding.bind(UsernamePasswordMultiBinding.java:76) at org.jenkinsci.plugins.credentialsbinding.impl.BindingStep$Execution.start(BindingStep.java:114) at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229) at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153) at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108) at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1278) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1172) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)
Where does the credential ID taken from? how does this function works inside the groovy script? I also tried this other way that I read but It uses a class like obect oriented, and instead of usernamePassword it uses UsernamePasswordMultiBinding
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'artifactory', usernameVariable: 'username', passwordVariable: 'password']])
and it gives me following error:
[Pipeline] End of Pipeline java.lang.IllegalStateException: There is no body to invoke at org.jenkinsci.plugins.workflow.cps.CpsStepContext.newBodyInvoker(CpsStepContext.java:283) at org.jenkinsci.plugins.workflow.cps.CpsStepContext.newBodyInvoker(CpsStepContext.java:95) at org.jenkinsci.plugins.credentialsbinding.impl.BindingStep$Execution.start(BindingStep.java:118) at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229) at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153) at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108) at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1278) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1172)
I also installed credential plug in in which I store user and pass globally and created a user ID which I then use in "withcredentials" ( credentialsId: 'artifactory'), but I think that Id is not related at all. I did some research but is not quite well explained the use of this function, and if It can be used inside a groovyscript for a jenkins pipeline from SCM. Can some one please explain how can I achieve this? Adding the groovy script I have.