Search code examples
androidgitjenkinsjenkins-pluginsgit-push

Jenkins Git Publisher: How to commit code back to master after build?


I'm having some difficulty with Jenkins Git Publisher committing and pushing code back to master after my build. My build process increases a version number in one of my files and then I want to commit this file back into the repo, but I can't seem to get it to work.

In Source Code Management->Git, these are my settings:

  • Repository Name: Android
  • Branch Specifier: master
  • Checkout/merge to local branch: master

Then, in Git Publisher, these are my settings:

  • Push Only If Build Succeeds: checked
  • Merge Results: checked
  • Branch to push: master
  • Target remote name: Android
  • Notes: Note to push: Updating version
  • Notes: Target remote name: Android
  • Notes: Note's namespace: master

This is the output from Jenkins:

Pushing HEAD to branch master at repo Android
Adding note to namespace "master":
Updating version

Please help!


Solution

  • I think jenkins git publisher plugin is not doing anything like

    git add .
    git commit -m 'xxx'
    

    Plugin only perform push and optionally add note using git-notes.

    See notes here:

    https://github.com/hamsterready/jenkins-git-publisher-test/tree/refs/notes/master

    To achieve something like this: https://github.com/hamsterready/jenkins-git-publisher-test/commit/d80a1eef2133bee6d7a57b1b229ccd5990d2d606

    I have added post-build step (execute shell script) with:

    git add .
    git commit -m 'Updating git.properties'
    

    And then enabled git publisher post-build action which pushed local commit to origin.