Jump to content

git experts


erragulabi

Recommended Posts

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.

Link to comment
Share on other sites

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'
}

 

Link to comment
Share on other sites

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}
""")
}
}

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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...