How to make Jenkins filter files modified in last commit and send them over FTP / SFTP

I have my own Bitbucket repository and I have Jenkins installed on the server. I have set up a project that creates assemblies when the Bitbucket repository is updated using push. I also configured "post-built actions" to send updated files over FTP / SFTP. Everything works fine, except Jenkins sends the entire site to the target FTP account, no matter how I pushed the commit with the single file.

Just to mention that when I go to project / build / changes it only lists changed files. It looks like "send build artifacts over FTP" is unaware of this and is sending the whole workspace

In project > settings > post build actions > send build artifacts over FTP > Transfer set > Source files

I installed **

. Do I need to change this value?

Can anyone help me set up my Jenkins project to download only changed and new files? It is absurd to upload 2000 files, while only a few files where they are added / changed.

+3


source to share


1 answer


Why is this happening?

Jenkins sends the entire site to the target FTP account, no matter how I pushed the commit with one changed file.

Each commit is not just changed files. This is actually a snapshot of the entire working tree (project folder). This is probably why Jenkins is uploading the entire project, not just the modified files.

How to filter only changed files?

There is a way to filter files modified by the most recent commit (or the N most recent commit). Hope this helps you work out your final solution.

This only shows changed files:

git show --pretty="format:" --name-only HEAD

      



Supposed to copy them: (doesn't work for me due to different OS trying to port)

git log -1 --pretty=format:"%h" | xargs -I %id% git diff-tree --no-commit-id --name-only -r %id% | xargs -I % cp --parents % upd/

      

Use -number

instead -1

to search by the number of recent commits.

What to do in Jenkins.

Sorry, dont know exactly how to set up Jenkins. But what needs to be done:

  • Use the above command to copy the modified files to a folder outside the project.
  • Ask Jenkins to FTP them
  • Empty the folder for future reuse.

This solution has parts translated from ru.stackoverflow

0


source







All Articles