rezza72
rezza72

Reputation: 137

run gitlab jobs sequentially

I have two simple stages. (build and test). And I want jobs in the pipeline to run sequentially.

Actually, I want when I run the test job, it doesn't run until the build job was passed completely.

My gitlab file:

stages:
  - build
  - test

build:
  stage: build
  script:
    - mvn clean package
    only:
    - merge_requests

test:
  stage: test
  services:
  script:
    - mvn verify
    - mvn jacoco:report
  artifacts:
    reports:
      junit:
        - access/target/surefire-reports/TEST-*.xml
    paths:
      - access/target/site/jacoco
    expire_in: 1 week
  only:
    - merge_requests

Can I add

needs:
    - build

in the test stage?

Upvotes: 4

Views: 1380

Answers (1)

Simon Schrottner
Simon Schrottner

Reputation: 4754

Based on the simplicity of your build file, i do not think that you actively need the needs. Based on the documentation, all stages are executed sequentially.

The pitfall you are in right now, is the only reference. The build stage will run for any branch, and for that ignore merge requests. if you add a only directive to your build job, you might get the result you are looking for like:


build:
  stage: build
  script:
    - mvn clean package
  only:
    - merge_requests
    - master # might be main, develop, etc. what ever your longliving branches are

This way it will not be triggered for each branch but only for merge requests and the long living branches. see the only documentation. Now the execution is not assigned to the branch but to the merge request, and you will have your expected outcome (at least what i assume)

Upvotes: 1

Related Questions