3

I've the html report generated under the artifacts folder for a given job, now I want to make that HTML report to be available in one of the nginx hosted web server (http://some_domain_name:8080).

my .yml file looks like below:

job:
    artifacts:
      name: "artifact_name"
      paths:
        - artifacts
      expire_in: 7 days
  

I think I'm able to download the artifacts using below API and extract the html report:

curl --location --output artifacts.zip --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts"

Is there a way that we can configure .yml file to make that html file from the artifacts folder to be available on a nginx web server ?

Many thanks in advance!

User123
  • 1,498
  • 2
  • 12
  • 26

1 Answers1

2

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).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250