1

Hi I want to push in Jenkins pipeline script.

I registered git id/pw in Jenkins credentials.

I succeeded git clone. This is git clone script

git branch: "develop", credentialsId: "mygitid", url: "mygiturl"

Now I want to commit & push.. but I don't know how to do this.. Anyone have idea?

seok0.2
  • 29
  • 5

1 Answers1

1

It is possible to push from a Jenkins pipeline, using the Credentials Binding pugin

stage('git push') {
    steps {
        withCredentials([
            gitUsernamePassword(credentialsId: 'mygitid', gitToolName: 'Default')
        ]) {
            sh '''
                 # modify some files
                 git add .
                 git commit -m "register work"
                 git push
            '''
        }
    }
}

This assumes you remain on the default cloned branch (usually 'main')

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for your answer, it working good . Can I ask question? – seok0.2 Jan 31 '23 at 04:52
  • Thank you for your answer, it working good . Can I ask question? Push result is 'remote : To create a merge request for develop, visit:' is it working success?? Because my coworker fail to git pull.. – seok0.2 Jan 31 '23 at 04:57
  • 1
    @seok0.2 The push work. Which means a pull should too, provided you are on the same branch. The PR message regards merging `develop` to the `main` branch. But in your case, as long as your colleague does a `git switch develop` first, and then a `git pull`, the code pushed should be present on their working tree. – VonC Jan 31 '23 at 07:13