Jenkins: rsync from built workspace or pull from original repository and build again
https://softwareengineering.stackexchange.com/questions/344187
-
08-01-2021 - |
Pergunta
I'm currently setting up a Jenkins pipeline for a web application and am wondering which methods of deployment are most common or recommended.
Currently Jenkins polls the SCM for new commits and triggers build when there are new commits.
Assume that the build process is:
composer install
phpunit tests
rsync workspace to staging server
behat --profile staging
Question is how to deploy?
Should I rsync the files directly from the jenkins workspace which have already run the build process and passed unit tests? Or should I hold a clone of the repository on the staging/production servers and trigger a git pull
and then a subsequent build on the server to deploy to?
Or anything else I haven't thought of?
Solução
I would deploy directly from the Jenkins workspace. The reason is that if you're performing git pull, it may pull newer version than what Jenkins built. Of course, "git checkout SHA1" could save your day, but really, if the Jenkins server is compatible with the deployment server, there is no reason to spend additional time to re-compile the thing.
Of course, if your web application is written using C or a similar language (unlikely as they aren't often used for web applications), there is theoretical possibility that the shared library version numbers on the Jenkins server and the deployment server differ. So, in this case, recompilation may be necessary.
My advice thus would be to try first deploying directly from the Jenkins workspace. If for some reason it does not work, then switch to using git pull and recompiling.