0

I have following docker command in gitlab CI file .gitlab-ci.yml

docker build --pull -t "${CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG}" .

getting following error after build stage:

invalid argument "." for "-t, --tag" flag: invalid reference format See 'docker build --help'.

any help , how to pass the variables ? Thanks

user2315104
  • 2,378
  • 7
  • 35
  • 54

1 Answers1

1

The way you've defined the tag is incorrect, and the result will be an empty string. That's why you get an error regarding the tag.

There is no need to add brackets, and you can use $ENV_VARIABLE. In this case, you can use the following command:

docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" .

If you want to use brackets:

docker build --pull -t "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}" .
Reza Ebrahimpour
  • 814
  • 6
  • 20
  • I used the first option without brackets : getting below error – user2315104 Aug 06 '21 at 07:10
  • At C:\Windows\TEMP\build_script133493204\script.ps1:249 char:25 + docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" . + ~~~~~~~~~~~~~~~~~~~ Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : InvalidVariableReferenceWithDrive – user2315104 Aug 06 '21 at 07:10
  • Did the second option (using brackets) work for you? And are you using Windows as the host OS for your Gitlab? If yes, maybe you should take a look at the documentation: https://docs.gitlab.com/ee/ci/variables/#use-cicd-variables-in-job-scripts – Reza Ebrahimpour Aug 06 '21 at 12:46
  • This link may also help you: Powershell - Variable reference is not valid. ':' was not followed by a valid variable name character https://stackoverflow.com/a/61582833/3907548 – Reza Ebrahimpour Aug 06 '21 at 12:51