james
james

Reputation: 19

How can we push changes from one github account to another github account using Jenkins pipeline?

I have a jenkins pipeline project which does the checkout from my github repository as shown below Jenkins pipeline SCM

Any changes updated in my github repository should be reflected in github repository of another account with the same folder strcuture using Jenkins pipeline. Got any ideas on how to proceed with this?

I have attached my pipeline script and the console output in the following images Pipeline Script Console Output

Upvotes: 0

Views: 336

Answers (1)

VonC
VonC

Reputation: 1324278

Assuming your other GitHub repository:

  • should mirror the history of your first GH repository,
  • has your first account added as a collaborator

You could make your pipeline do a git push "withCredentials", as in here.

withCredentials([usernamePassword(credentialsId: 'fixed',
                 usernameVariable: 'username',
                 passwordVariable: 'password')]){
    sh("git push http://$username:[email protected]/repo")
}

See "Credentials Binding Plugin": you can use variable or dsecret file for the password.

Upvotes: 1

Related Questions