Sometimes, when you are running the base image, you would like to have some commands to be executed on every job, for example, installing a package or updating a specific library, etc.
Adding the same commands over and over again will produce a lengthy workflow file.
Some services provide a section called
before_script which should host all the commands we want to execute before each job.
before_job top section (same level with name/on/jobs) will help make the code less cluttered and more organized.
Same thing for
container why we should repeat them within each job if all the jobs need them?
I am not saying that all jobs will have access to the same service/container. Instead, we are going to separate the repeated code, and each job will create its own service and attach it to the job or use the container to execute the commands.
Also with the ability to define services/container within the job which will then used instead of the general one defined at the top level.