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:
Then, in Git Publisher, these are my settings:
This is the output from Jenkins:
Pushing HEAD to branch master at repo Android
Adding note to namespace "master":
Updating version
Please help!
These work in some Jenkins plugins, but not all, so it might not work in the Git Publisher. I recommend to configure fully qualified /refs/remotes/origin/feature-1234 as your Git "Branch to build".
In this tutorial, How to use Jenkins auto-build when git commit. You use a webhook to capture when a new git commit was made and Jenkins will start to build jobs. Ref to Install Jenkins on AWS EC2. Install the Git and Github plugins.
Under Source Code Management, choose ‘Git’. Add the URL of the repository and the credentials. (Jenkins will attempt to authenticate against this URL as a test, so it should give you an error promptly if the authentication fails.) Use the commit hash given when the job was started by typing $ {COMMIT_HASH} in the Branch Specifier field.
From the Jenkins home page, click on Demo in the Name column. Make sure “Branch Specifier” for Branches to build is blank. For Additional Behaviors, add Merge before Build. Set the name of the repository to origin. Set the branch to merge to master. Add the Post Build Action Git Publisher. Select Push Only If Build Succeeds. Select Merge Results.
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.
If you are using also Gradle for your builds, there is a Git plugin for it.
Here is the complete build.gradle
:
buildscript {
repositories { mavenCentral() }
dependencies { classpath "org.ajoberstar:gradle-git:0.6.3" }
}
import org.ajoberstar.gradle.git.tasks.*
task tag(type: GitTag) {
tagName = version
message = "Release of $version"
}
task pushWithTags(type: GitPush){
credentials{
username = "karim"
password = gitPassword
}
setPushTags(true)
}
task add(type: GitAdd){
include("yourVersionFile.txt")
// or add everything with include("*")
}
task commit(type: GitCommit){
setMessage(commitMsg)
}
task pushNewVersion(){
tasks.add.execute()
tasks.commit.execute()
tasks.tag.execute()
tasks.pushWithTags.execute()
}
This is how you add, tag, commit, and push using the script (there is a plugin for doing that from within Jenkins):
gradle pushNewVersion "-PcommitMsg=hi" "-Pversion=0.1.1" "-PgitPassword=secret"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With