Middle
What is the difference between needs and dependencies in GitLab CI?
sobes.tech AI
Answer from AI
In GitLab CI, the needs and dependencies keys are used to control the execution order and artifact transfer between jobs, but they serve different purposes.
-
needs — determines which jobs the current job depends on for execution. It affects the order of execution and allows jobs to run in parallel if dependencies are satisfied. It is used to optimize pipeline time.
-
dependencies — specifies from which jobs to download artifacts for the current job. This is important if artifacts are needed for the job to work but do not necessarily influence the execution order.
Example:
job1:
script: echo "build"
artifacts:
paths:
- build/
job2:
needs: [job1] # job2 will run after job1
dependencies: [job1] # job2 will download artifacts from job1
script: echo "test"
Thus, needs manages the order and parallelism, while dependencies handles artifact transfer.