[JIRA] (JENKINS-50702) jenkins pipeline with groovy and use of “Withcredentials”

88 views
Skip to first unread message

guillecasco1@hotmail.com (JIRA)

unread,
Apr 9, 2018, 5:18:02 PM4/9/18
to jenkinsc...@googlegroups.com
guillermo casco created an issue
 
Jenkins / Story JENKINS-50702
jenkins pipeline with groovy and use of “Withcredentials”
Issue Type: Story Story
Assignee: Stephen Connolly
Attachments: Extractor.groovy
Components: credentials-plugin
Created: 2018-04-09 21:17
Priority: Minor Minor
Reporter: guillermo casco

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.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

guillecasco1@hotmail.com (JIRA)

unread,
Apr 16, 2018, 8:47:02 AM4/16/18
to jenkinsc...@googlegroups.com
guillermo casco closed an issue as Fixed
Change By: guillermo casco
Status: Open Closed
Resolution: Fixed

stephen.alan.connolly@gmail.com (JIRA)

unread,
Apr 16, 2018, 10:02:02 AM4/16/18
to jenkinsc...@googlegroups.com
Stephen Connolly assigned an issue to Unassigned
Change By: Stephen Connolly
Assignee: Stephen Connolly

stephen.alan.connolly@gmail.com (JIRA)

unread,
Apr 16, 2018, 10:02:05 AM4/16/18
to jenkinsc...@googlegroups.com
Stephen Connolly updated an issue
Change By: Stephen Connolly
Component/s: credentials-binding-plugin
Component/s: credentials-plugin
Reply all
Reply to author
Forward
0 new messages