Build Docker image only if Code Repository has been updated (Jenkins)
Currently, in a Jenkins job, I build a Docker image with files from a git repository. When this repository is changed/updated I would like to either:
- Be able to detect this in Jenkins so I can change my Bash script to rebuild the Docker image from my Dockerfile
- Find some other method of building my Docker image that does not require me to build it every time I run the Jenkins job (I run the job hourly, and it takes nearly 10 minutes to build the Docker image)
What is a clean and efficient solution to this? Should I just build the image every time I run the job after all?
2 Solutions collect form web for “Build Docker image only if Code Repository has been updated (Jenkins)”
This one is simple, first what are you using to host your git? hopefully github / gitlab? if so, “polling” SCM like @amit mentioned is overkill.
why let jenkins look for changes, when the git server can alert jenkins on changes?
What you want to do is set up a jenkins job that builds a docker image for you
then on either github/gitlab, set up a web hook (project settings -> web hooks) to the jenkins project.
this way, when you push changes to GH/GL, it will send a payload to jenkins, which would then run your build project
You can configure a “Poll SCM” build trigger – this will cause Jenkins to periodically check your git repository for changes and the build step will be triggered only if changes are detected. (I assume your build step will be doing the
You can find more information here – https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-Buildsbysourcechanges