Help me Understand artifacts and deploy

Problem to solve

I have issue to well understand how artifacts and jobs works in real world ‘perfect’ ci/cd configuration.

In web project context the test and build steps use sources file and dependancies. Not all that files are needed in running environment.

For now I split my pipeline in test, build, deploy steps(jobs).
As you can imagine i need to keep some files between steps (artifacts) and in last one deploy throught for ie scp.

Where my troubles/miss understanding occurs :

  • in artefacts managment mostly.

Can artifacts can be retrieve automaticly as zip from one step to another ?
Should i create the zip myself ?
Can I create a reusable step in that case. A step that automaticly take artifacts from previous steps and zip/tgz with variables based name and use in deploy steps ?

Not sure i explain myself clearly.

my current pseudo code/file have and want to achieve :


testing-build:
    stage: testing-build
    tags:
      - tag0
      - tag1
      - tag2
    script:
      - echo "Building the application"
      - wget https://getcomposer.org/download/latest-stable/composer.phar
      - php ./composer.phar self-update
      - php ./composer.phar install --prefer-dist --no-scripts -o --no-cache
      - npm config ls -l
      - npm clean-install
    only:
      - master
    artifacts:
      expire_in: 1 month
      paths:
        - vendor/
        - app/
        - artisan/
        - bootstrap/
        - config/
        - database/
        - [...]

# several lines after
testing-deploy:
  stage: testing-deploy
  environment:
    name: Testing
    deployment_tier: testing
    url: https://stuff.tests.lan
  rules:
    - when: manual
  variables:
    DEPLOY_ENV: "testing"
  before_script:
    - ssh stuff
  script:
    - echo "Deploying to $DEPLOY_ENV environment"
    - scp ~/${artefacts}.zip "$testing_user"@"$testing_host":~/
    - |
      ssh "$testing_user"@"$testing_host" << END_TEXT
        echo 'ssh connected '
        unzip -qq "${artefacts}.zip"
        # other stuff
      END_TEXT

hi, small update.