I will assume you are using an on-premise GitLab instance with self-manager runners, considering your GitLab runner will need network access (for instance, SSH access) to your NGiNX server.
If that is the case, then you can indeed, after downloading the artifact:
- Unzip and extract the artifact.
- Upload the HTML file to the Nginx server, with for instance tools like
scp
or rsync
to move the HTML file from the GitLab runner to your Nginx server.
- make sure the file permissions and ownership are set correctly on the Nginx server, so the web server can read and serve the file.
stages:
- deploy
deploy_to_nginx:
stage: deploy
script:
- apt-get update -y && apt-get install -y unzip curl rsync
- curl --location --output artifacts.zip --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts"
- unzip artifacts.zip
- rsync -avz -e "ssh -o StrictHostKeyChecking=no" ./artifacts/report.html username@nginx_server_ip:/path/to/nginx/root/directory/
only:
- main # or whichever branch you want to deploy from
This pipeline step should be executed after your current job that produces the artifact, or you can add the above steps to your current job script.
You would need to replace:
username@nginx_server_ip
should be replaced with the actual username and IP address (or domain) of your Nginx server.
/path/to/nginx/root/directory/
should be replaced with the actual path where Nginx is serving static files from.
And you would need a public key of the runner added to the ~/.ssh/authorized_keys
file of the target user on the Nginx server.
StrictHostKeyChecking=no
is added to avoid manual verification of the Nginx server's fingerprint. While this simplifies the process, this is for testing, as it could be a security risk. It is more secure to add the Nginx server's SSH fingerprint to the GitLab runner's known hosts beforehand (as in "GitLab CI — SSH with Passphrase deploy example" from Pablo Daniel González).