Skip to content
GitLab
Next
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    Projects Groups Topics Snippets
  • Register
  • Sign in
  • gitlab-runner gitlab-runner
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 3,455
    • Issues 3,455
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 110
    • Merge requests 110
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • gitlab-runnergitlab-runner
  • Merge requests
  • !3158

Add variable support for services

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Stefano Tenuta requested to merge ST-Apps1/gitlab-runner:23671-add-variables-to-ci-services into main Oct 08, 2021
  • Overview 55
  • Commits 18
  • Pipelines 16
  • Changes 6

What does this MR do?

Currently, the only way to pass environment variables to a Docker/Kubernetes service during CI is to provide them inside the job's variables. This MR adds the possibility to declare an additional set of variables for the services, making them closer to the docker-compose spec.

Please note that it's my very first time using Go so there might be some issues that I'd be glad to fix with your help.

Why was this MR needed?

This is related to gitlab!72025 (merged), which aims to close gitlab#23671 (or at least to provide an initial solution).

What's the best way to test this MR?

  1. Setup a new project
  2. Register either a Docker or a Kubernetes executor
  3. Create a new .gitlab-ci.yml file with the following contents
     image: busybox:latest
    
     variables:
       GIT_STRATEGY: none
    
     stages:
       - build
    
     Build With A Service And Some Variables:
       stage: build
       image: curlimages/curl
       services:
       - name: ealen/echo-server:latest
         alias: echo-server
         variables:
           PORT: 5000
           ENABLE__ENVIRONMENT: 'true'
           ENV_VAR_FOR_SERVICE: "This is a variable passed to the service"
       script:
         - curl echo-server:5000/?echo_env_body=ENV_VAR_FOR_SERVICE
    
     Build With A Service And No Variables:
       stage: build
       image: curlimages/curl
       services:
       - name: ealen/echo-server:latest
         alias: echo-server
       script:
         - curl echo-server:80/
    
     Build Without A Service:
       stage: build
       image: busybox:latest
       script:
         - echo "Build Without A Service"
Edited Feb 01, 2022 by Arran Walker
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: 23671-add-variables-to-ci-services