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?.
I´m attaching my groovy script so you can see.
If is not this way, how can I achieve to use user and pass on job output but that they don´t appear (or appear like ***)
...
stage ('Upload war to Artifactory') {
withCredentials([usernamePassword(credentialsId: 'artifactory', usernameVariable: 'user', passwordVariable: 'password')]) { sh "sudo curl -u $user:$password -T $warPath 'https://artifactory.xxxxxx.com:443/artifactory/form/$warFile'" }
}
...