Add variable with network name when using FF_NETWORK_PER_BUILD

What does this MR do?

This MR adds the CI_BUILD_NETWORK_NAME variable, which represents the network name created by the runner for this job. The variable is only exposed when the FF_NETWORK_PER_BUILD feature flag is enabled.

Why this MR needed?

This MR completes the work from !5132 (closed), which was never merged, with additional improvements and fixes. The community has requested this variable for a long time. For more information, see #26718 (closed).

Example:

Below is an example of a use case where we want to build a Docker image on the same network as the services:

build-artifact:
  stage: build
  tags:
    - docker-builder
  services:
    - name: redis:alpine
      alias: redis
    - name: mysql:5.6
      alias: mysql
    - name:    'docker.elastic.co/elasticsearch/elasticsearch:6.3.2'
      alias: es
      entrypoint: ["/bin/bash"]
      command: ["-c", "env discovery.type=single-node docker-entrypoint.sh eswrapper"]
  image: docker
  script:
    - docker build
        --pull
        --network ${CI_BUILD_NETWORK_ID}
        -t docker.example.com/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}
        -f build/ci/Dockerfile .
    - docker login -u user -p password docker.example.com
    - docker push docker.example.com/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}
  after_script:
    - docker logout docker.rsvx.it

#26718 (closed) !5132 (closed)

Edited by Pishel

Merge request reports

Loading