I am trying to use Jenkins CI server for my PHP application. As we are using our Git repository so i am using jenkins's git plugin to take files from central repo.
Currently when my jenkins job runs it takes files from git repo & make a build but that build contains all the files.
As per my current scenario i only want modified+new files in that build.So that i can deploy only them not the whole bunch of files.
Is this possible somehow..or it is fundamentally wrong in build environments..?
You need two things: The commit of the previous build and then the changed files between the previous build commit and current HEAD.
For the first: There might be ways to find the commit from Jenkins via the REST API (as it does display it in the build page. But I think it will be easier if you put the git commit into a file and archive it as a build artifact. Then you can use Copy Build artifacts plugin to get the file from the previous build.
For the second: Maybe you can use git diff --name-status HEAD
To tie all of this together:
Set up the build to Copy artifacts from the same job, last successful build.
Assuming the file where you store the commit id is called "commit_id", set a build step to run something like:
git diff --name-status `cat commit_id` HEAD |
while read status file; do
case $status in
D) echo "$file was deleted" ;; # deploy (or ignore) file deletion here
A|M) echo "$file was added or modified" ;; # deploy file modification here
esac
done
# record this commit to be archived
git describe > commit_id
In the post build actions, configure the job to archive the file commit_id.
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