Accessing postgresql in review stage of Gitlab CI/CD

Viewed 184

How do I import data to the postgresql server during the Review stage (for a review app) during the Gitlab CI/CD process?

I am currently using Gitlab CI/CD to deploy to AWS. Postgresql is used throughout the build stages.

During the build stages, information is successfully imported to postgresql from another application. The data is then dumped as a SQL file to an artifact (in two locations).

artifacts:
    paths:
      - postgres_backup.sql
      - scripts/postgres/postgres_backup.sql
    expire_in: 1 day

The build artifacts are created. However, they are not available in the review - autodeploy - stage. The review stage is basically:

review:
  extends: .auto-deploy
  stage: review
  before_script:
    - echo "Supposedly, this helps to carry over artifacts." 

The artifacts are not there. Ideally, I would want to push the SQL backup to the database but 1) the artifact is not available and 2) the psql command is not available (nor apt).

1 Answers

Take a look at the .auto-deploy job (it might be coming from an included job this too). If the .auto-deploy job has a dependencies keyword, it's affecting your artifacts.

By default, when one job uploads artifacts, jobs in all following stages will automatically download the artifact. This can be controlled using the dependencies keyword on individual jobs.

For example, using dependencies: [] means this job has no dependencies, so no artifacts are downloaded. dependencies: ["npm install job"] means that the artifacts from a job called "npm install job" are the only artifacts downloaded, even if artifacts from other jobs are uploaded.

So if you see the dependencies keyword in the .auto-deploy job, you'll have to include it in your review job. If .auto-deploy has dependencies: [], you'll have to have dependencies: ["your-job-name"] where the job name is the job that uploads the files.

If .auto-deploy has a dependencies keyword that has at least one job name, you'll have to copy the jobs, and include them in your review job:

// .auto-deploy job:
.auto-deploy
  stage: deploy
  dependencies: ["job1", "job2"]
  script:
   - ...
// review job
review:
  stage: review
  dependencies: ["job1", "job2", "your-postgres-job"]
  script:
    - ...
Related