Jump to content

git experts


Recommended Posts

Posted

I have a branch name which I need to commit to remote master. I am planning to do this from Jenkins. I want to pass the command something like git push branch name. I don't want to use scm for this task. Any help appreciated. Calling @Spartan and others.

Posted

@erragulabi  git plugin with credentials untadi...u can use that..

a credentials ki u need to provide write access and use that in stage.

Posted

something like.

withCredentials([usernamePassword(credentialsId: 'amazon', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
  // available as an env variable, but will be masked if you try to print it out any which way
  // note: single quotes prevent Groovy interpolation; expansion is by Bourne Shell, which is what you want
  sh 'echo $USERNAME'
  // also available as a Groovy variable
  sh 'git push'
}

 

Posted

i want to write this as a script as i have to pull info of branch name from a table in DB.

Posted
2 minutes ago, erragulabi said:

i want to write this as a script as i have to pull info of branch name from a table in DB.

hmm aite  u need to first get the git credentials as env variables, and do git global config in the script  and then do ur stuff.

kinda `sh` script lo u can do whatever u want to..like pull the branch name.




stage("Git creds"){
withCredentials(usernamePassword(credentialsId: GIT_CREDS, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME'){
sh("""
git config --global credential.username {GIT_USERNAME}
git config --global credential.helper "!echo password={GITPASSWORD}; echo"
git push {your_repository}
""")
}
}

 

Posted
47 minutes ago, Spartan said:

hmm aite  u need to first get the git credentials as env variables, and do git global config in the script  and then do ur stuff.

kinda `sh` script lo u can do whatever u want to..like pull the branch name.





stage("Git creds"){
withCredentials(usernamePassword(credentialsId: GIT_CREDS, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME'){
sh("""
git config --global credential.username {GIT_USERNAME}
git config --global credential.helper "!echo password={GITPASSWORD}; echo"
git push {your_repository}
""")
}
}

 

thanks spartan. 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...