Here's a follow up to the discussion we had in the comments to your question.
Setting up the deploy keys and the pipeline
First generate a SSH key pair. You can use ssh-keygen -t rsa
for that.
Then create a gitlab project for the page, let's call it projectname-docs
. In this project, locate the Deploy Keys
setting. There you should paste the public key you just generated.
Then go to projectname
and locate the Variables
page. Create a new private variable with the name SSH_PRIVATE_KEY
for instance and paste the private key you generated there.
In your .gitlab-ci.yml
file in the projectname
project, add the following so that your private key will be available to your CI environment:
pages:
stage: deploy
script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- git clone git@gitlab.com:groupname/projectname-docs.git
- cd projectname-docs
- mkdir ~/.public
- cp -r * ~/.public
- cd ../
- mv ~/.public public
artifacts:
paths:
- public
At this point, every time you push something to your main project, it will pull the projectname-docs
project and deploy it using Gitlab pages. The docs should then be available.
Setting up the webhook
What you may want, is to be able to run the main project's pipeline every time you push to projectname-docs
so the web page is updated.
One way to do this is through webhooks.
First go to your main project's gitlab page and go to Settings -> CI/CD Pipelines -> Triggers
and click the Add Trigger
button. This will create a new token we'll use later.
Then, go to projectname-docs
and navigate to Settings -> Integrations
and insert the following for the URL:
http://gitlab.com/api/v4/projects/ID/ref/REF_NAME/trigger/pipeline?token=TOKEN
Where ID
is the id of projectname
, REF_NAME
is the name of the branch or tag to run the pipeline for (e.g master
) and TOKEN
is the token you generated in the previous step.
Make sure the push
event is selected and add the webhook.