Correct me if I’m on the wrong track here, but I want to build my own Docker image during the pipelines and therefor need to clone the repository (Maybe this can be done before the Dockerfile, in gitlab-ci.yml?)
I’m trying to run something like this:
RUN git clone --progress https://$USER:$PASSWORD@gitlab.com/$REPOSITORY -b $BRANCH .
But I have failed to understand, how I can pass variables from the Gitlab runner into my Docker image?
(I can see some suggested topics on this, but none of them have any replies)
When you run a pipeline, the repo for your project is automatically downloaded. By default, your before_script, script, and after_script commands will start from the root of your repo. So, you shouldn’t need to clone from the Dockerfile, unless you need to clone a different repo, for some reason.
This blog post shows an example .gitlab-ci.yml which builds a Dockerfile.
It will be a directory stored in CI_PROJECT_DIR (docs here), but your code from .gitlab-ci.yml will run from that directory, so you don’t need to cd to the directory.
Right, so I think there are a couple of different questions here. Your .gitlab-ci.yml file looks OK to me, and if it’s building a Docker image then that should be fine.
If you want specific files from the repo to be added to your Docker image, then you will need to use ADD or COPY in your Dockerfile to do that. However, you should not need to clone the repo again, because the GitLab CI runner has already cloned the repo for you, before your script from your build stage has run.