Hi,

I changed my code to post it here and during that i changed the dir name. I 
wouldn't worry about naming standards yet, the bigger problem for me is 
that it is not working.

I saw some code snippets claiming withcredentials to be working the way i 
have posted. Don't know what is the issue here. 

On Saturday, 6 May 2017 01:56:09 UTC+2, Ramanathan Muthaiah wrote:
>
> On Friday, May 5, 2017 at 3:32:36 PM UTC+5:30, ishan jain wrote:
>>
>> I am trying to push some tags back to repository and for obvious reasons, 
>> i would like to keep my usernam/pass hidden. I use withcredentials for this 
>> and the code looks like this:
>>
>> checkout([$class: 'GitSCM', branches: [[name: '*/master']], 
>> doGenerateSubmoduleConfigurations: false, extensions: [[$class: 
>> 'RelativeTargetDirectory', relativeTargetDir: 'git']], submoduleCfg: [], 
>> userRemoteConfigs: [[url: 'http://my-GITBUCKET-gitURL.git']]])
>>
>>         
>> dir ('git') {
>>
>> withCredentials([usernamePassword(credentialsId: 
>> '11111111-1111-11111-11111-111111122222', usernameVariable: 'GIT_USERNAME', 
>> passwordVariable: 'GIT_PASSWORD')]) {
>> sh "git credential approve"
>> sh 'git tag -a ' + env.BUILD_ID + ' -m "Creating tag"'
>> sh "git push origin " + env.BUILD_ID
>> }
>> }
>>
>> This always gives me the following error:
>>
>> 09:45:12 [git] Running shell script
>> 09:45:13 + git push origin 124
>> 09:45:13 fatal: could not read Username for '
>> http://my-GITBUCKET-gitURL.git': No such device or address
>>
>> I tried learning more about this error and seems like it should have been 
>> working after using GIT approve, but apparently it is not.
>>
>> I tried something like below and *it works fine, only that it is an ugly 
>> workaround* and i do not with to use as a final solution.
>>
>> checkout([$class: 'GitSCM', branches: [[name: '*/master']], 
>> doGenerateSubmoduleConfigurations: false, extensions: [[$class: 
>> 'RelativeTargetDirectory', relativeTargetDir: 'git']], submoduleCfg: [], 
>> userRemoteConfigs: [[url: 'http://my-GITBUCKET-gitURL.git']]])
>>
>>         
>> dir ('git') {
>>
>> withCredentials([usernamePassword(credentialsId: 
>> '11111111-1111-11111-11111-111111122222', usernameVariable: 'GIT_USERNAME', 
>> passwordVariable: 'GIT_PASSWORD')]) {
>> sh "git credential approve"
>> sh 'git tag -a ' + env.BUILD_ID + ' -m "Creating tag"'
>> sh "git push 
>> http://${GIT_USERNAME}:${GIT_PASSWORD}@${repoURL.substring(7)} --tags"
>> }
>> }
>>
>  
> So, the URL with username and password is working (as expected).  If you 
> are using withCredentials (meta-step ?) with credentials id, username and 
> password are variables that help to store authentication info that can be 
> used for git operations.
>
> Have you looked at the console log, these values will be masked and 
> displayed as asterisks ?
>
> BTW, you should avoid having generic names, like, 'git' within dir() as 
> seen in the code snippet shared by you.
> It should reflect the purpose for which is meant for, like, it could be 
> same as the repo name that you are trying to update with new commits.
>
> /Ram
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/f5591dbd-f097-473a-918b-7f838ae97938%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to