Creating sequential jobs for the build stages

I would like to create multiple jobs for build stage, but being able to run them sequentially, example:

stage 1: build Java artifact.
stage 2: build a Docker image and push to registry.

Both are build stages, but they run in parallel if specifying:

build_java:
   stage: build
   script:
     - mvn clean package -P production -T 2C

build_docker:
   stage: build
   script:
     - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
     - docker build -t $IMAGE_NAME .
     - docker push $IMAGE_NAME

How to execute the stages above sequentially?

You would need to put them in separate stages, the one running after the other. Jobs in a single stage run in parallel.

Checkout https://docs.gitlab.com/ee/ci/pipelines/pipeline_architectures.html#directed-acyclic-graph-pipelines
You can do a DAG with using needs on the previous job.

Actually, DAG is way over-complicated for your needs. You just need to remove the stage: build property from both jobs and they should be run in sequential order.

I WAS WRONG - just checked

This is what you need

stages:
   - build:jvm
   - build:docker
build_java:
   stage: build:jvm
   script:
     - mvn clean package -P production -T 2C

build_docker:
   stage: build:docker
   script:
     - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
     - docker build -t $IMAGE_NAME .
     - docker push $IMAGE_NAME

WTF I just realized what a necro-post this is! @l4-eisenreich why would you reply to a 3-year old post?

I was searching for gitlab ci run jobs sequentially and the first item was this. So now the next one who is searching for the same topic, has a answer with the appropriate doc.

Can’t argue with that.

Ofc, I can delete my post… I do already have the answer :smile: