erragulabi Posted October 5, 2020 Report Posted October 5, 2020 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. Quote
Spartan Posted October 5, 2020 Report Posted October 5, 2020 @erragulabi git plugin with credentials untadi...u can use that.. a credentials ki u need to provide write access and use that in stage. Quote
Spartan Posted October 5, 2020 Report Posted October 5, 2020 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' } Quote
erragulabi Posted October 5, 2020 Author Report Posted October 5, 2020 i want to write this as a script as i have to pull info of branch name from a table in DB. Quote
Spartan Posted October 5, 2020 Report Posted October 5, 2020 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} """) } } Quote
erragulabi Posted October 5, 2020 Author Report Posted October 5, 2020 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.