How to deploy only modified/new files GIT+Jenkins+PHP? How to deploy only modified/new files GIT+Jenkins+PHP? jenkins jenkins

How to deploy only modified/new files GIT+Jenkins+PHP?


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    esacdone# record this commit to be archivedgit describe > commit_id

In the post build actions, configure the job to archive the file commit_id.


There is nothing "fundamentally wrong" in that, however at least your release builds should be "clean full" builds (not incremental).

As for "how" to do that... you have to do that yourself. Haven't seen any plugins like this. Why? Because in majority of compiled "builds", there is no 1-to-1 relationship between a source file and corresponding compiled file. How would the system know which new files produced which new artifacts? (In PHP, it's clear, in other languages, not)

You've got to write your own build script that would:

  • Parse the console log for SCM changes, or query the SCM directly.
  • Build
  • Archive/Package/Zip only the files that were changed, based on your parsing in step 1.
  • Deploy that subset of file.