GitLab: Automate with the CLI

Start GitLab, retrieve its credentials, and change its configuration programmatically with the Stackhero CLI

👋 Welcome to the Stackhero documentation!

Stackhero provides a ready-to-use GitLab cloud solution designed for teams that need a fast, secure, and scalable environment:

  • Unlimited users, repositories, data transfers, and CI/CD processing time for complete flexibility.
  • Effortless updates with a single click, so your environment stays current without downtime.
  • Custom domain name secured with HTTPS (for example, https://git.your-company.com) for professional branding and security.
  • Consistent performance and strong security on your own private, dedicated infrastructure. There are no noisy neighbors and you have full isolation.
  • Choice of hosting location: 🇪🇺 Europe or 🇺🇸 USA to suit your compliance or latency needs.

Get started fast and focus on your code. Stackhero's GitLab cloud hosting solution is ready to use in about 5 minutes.

This guide shows how to create a GitLab service, read its credentials, and update its configuration entirely from the command line, with no clicks in the dashboard. It is ideal for scripts, CI pipelines, and AI agents.

We will be using the Stackhero CLI for all tasks. If you have not already, you can install it with:

curl -fsSL https://www.stackhero.io/install.sh | sh

The easiest way to get started is by logging in through your browser. When you run the login command, the CLI opens a web page where you can approve access. No passwords or 2FA codes are entered into the CLI itself.

stackhero login

After logging in, your credentials are stored locally and will be used automatically by future CLI commands.

For fully automated environments like scripts or CI pipelines, you might prefer a non-interactive access token. You can create one from your dashboard (Account > Access tokens), then export it as an environment variable. The CLI, and any script you run, will pick it up automatically.

export STACKHERO_TOKEN="usr-xxxxxx:your-token"

Next, you will want to list the GitLab service stores available to your account. The CLI accepts the store name (gitlab) directly, so there is no need to look up or copy any IDs.

# List GitLab service stores (add --organization if you manage more than one)
stackhero services-store-list --name="gitlab"

You can refer to the store name gitlab in subsequent commands, or choose a specific svs-xxxxxx ID from the list if you prefer.

# List instance sizes for your service store (use the NAME column for --instance)
stackhero instances-store-list --service-store=gitlab

# List available regions (names like "europe")
stackhero regions-list

Here is a sample script that creates a stack, adds your GitLab service to it, waits for it to start, retrieves its configuration (including generated credentials), and then applies a new configuration.

#!/bin/bash
set -e

export STACKHERO_TOKEN="usr-xxxxxx:your-token"

serviceStore="gitlab"   # The GitLab service store name (see step 2)
instance="..."                # An instance size from step 3
region="europe"               # A region name from step 3

# Create a stack for your service (uses your default organization; add --organization if needed)
stackId=$(stackhero --format=script stack-create \
  --name="My GitLab stack")
echo "Stack created: ${stackId}"

# Add GitLab to the stack (names are resolved automatically)
serviceId=$(stackhero --format=script service-add \
  --stack="My GitLab stack" \
  --service-store="${serviceStore}" \
  --instance="${instance}" \
  --region="${region}")
echo "Service added: gitlab"

# Wait for the service to be fully running (this may take a couple of minutes)
stackhero service-wait-for --service="gitlab"

# Retrieve the service configuration, including generated credentials
stackhero service-configuration-get --service="gitlab" --format=json

The service-configuration-get command returns the complete configuration for your service, including auto-generated passwords and connection details. The output is in JSON format, making it easy to use in scripts and automation.

stackhero service-configuration-get --service=svc-xxxxxx --format=json

You can review an example configuration schema and then apply your own settings. When you update the configuration, the service may restart to apply the changes.

# View the configuration schema and an example for your service
stackhero service-configuration-example --service=svc-xxxxxx

# Apply a custom configuration (the service restarts if needed)
stackhero service-configuration-set \
  --service=svc-xxxxxx \
  --configuration='{ "...": "..." }'

# Wait for the new configuration to be applied
stackhero service-wait-for --service=svc-xxxxxx

That is it. You have now seen the full lifecycle: start a service, retrieve its credentials, and reconfigure it, all in a scriptable, automated way. To dive deeper, check out the full CLI documentation, which also covers the non-interactive STACKHERO_TOKEN authentication demonstrated here.