Masked GitLab CI variables need at least 8 characters
Today I ran into a small GitLab CI gotcha.
I wanted to store an SSH port as a masked CI/CD variable, but GitLab rejected it because masked values must satisfy stricter validation rules (including minimum length).
A short numeric port value can fail that check.
Related discussion: https://gitlab.com/gitlab-org/gitlab/-/work_items/465258
Workaround
Store a padded masked variable, then normalize it in CI.
Example:
DEPLOY_PORT_MASKED=00023456(masked, 8 chars)- Convert it back to an integer in the job:
DEPLOY_PORT="$((10#$DEPLOY_PORT_MASKED))"
export DEPLOY_PORT
Then use DEPLOY_PORT normally:
ssh -p "$DEPLOY_PORT" ...
Why 10# matters
10# forces base-10 parsing and safely strips leading zeros.
Without it, shell arithmetic can misinterpret leading-zero numbers in some cases.
Result
I can keep the value masked in GitLab and still use the intended port at runtime.