Docker Gitlab 上的跑步者 CI - 仅针对特定阶段的代理

Docker runner on Gitlab CI - Proxy only for specific stage

对于“部署”阶段,我需要一个代理。但是“测试”阶段从 Karma 测试开始的地方开始不起作用。有没有一种方法,我可以在其中定义:为“部署”阶段而不是“测试”阶段使用代理设置?

我试图从代理中排除 Karma 正在使用的 IP,但 IP 每次都在变化。

variables:
      http_proxy: "$CODE_PROXY"
      https_proxy: "$CODE_PROXY"
      no_proxy: "127.0.0.1,localhost"

stages:
  - test
  - deploy


test:
  stage: test
  image: node:erbium
  services:
    - selenium/standalone-chrome:3.141.59
  script:
    - npm ci
    - npm run lint
    - npm run lint:sass
    - npm run lint:editorconfig
    - npm run test -- --progress=false --code-coverage
    - npm run e2e -- --host=$(hostname -i)
    - npm run build:prod -- --progress=false
  coverage: '/Statements\s*:\s*(\d+\.?\d+)\%/'
  artifacts:
    expire_in: 3h
    paths:
      - dist/
    reports:
      junit: dist/reports/app-name/test-*.xml
      cobertura: dist/coverage/app-name/cobertura-coverage.xml
  tags:
    - DOCKER

deploy:
  stage: deploy
  image: python:latest
  script:
  - pip install awscli
  - aws s3 rm s3://$S3_BUCKET_NAME --recursive
  - aws s3 cp ./dist/app-name s3://$S3_BUCKET_NAME/ --recursive
  only:
  - master

两种方式

  1. 混合变量
.proxy-variables: &proxy-variables
      http_proxy: "$CODE_PROXY"
      https_proxy: "$CODE_PROXY"
      no_proxy: "127.0.0.1,localhost"

deploy:
  stage: deploy
  image: python:latest
  variables:
    - *proxy-variables
  script:
    - pip install awscli
    - aws s3 rm s3://$S3_BUCKET_NAME --recursive
    - aws s3 cp ./dist/app-name s3://$S3_BUCKET_NAME/ --recursive
  only:
    - master

  1. 扩展作业模板
.proxied-job:
  variables:
      http_proxy: "$CODE_PROXY"
      https_proxy: "$CODE_PROXY"
      no_proxy: "127.0.0.1,localhost"

deploy:
  extends: .proxied-job
  stage: deploy
  image: python:latest
  script:
    - pip install awscli
    - aws s3 rm s3://$S3_BUCKET_NAME --recursive
    - aws s3 cp ./dist/app-name s3://$S3_BUCKET_NAME/ --recursive
  only:
    - master