Gitlab 根据提交消息,从同一手动作业为不同环境部署

Gitlab 根据提交消息,从同一手动作业为不同环境部署,gitlab,gitlab-ci,gitlab-ci-runner,Gitlab,Gitlab Ci,Gitlab Ci Runner,我有10个环境。每个环境都应该有相同的手动作业来部署5个服务(5个按钮)。environment-1作业和environment-2作业之间的唯一区别是标记,变量。仅检查提交消息和环境。名称。 例如,我应该能够在提交消息中指定[staging],并具有5个单独的按钮,用于将5个服务部署到staging。同样适用于[生产]等 staging-deploy-service1: <<: *deploy environment: name: staging variabl

我有10个环境。每个环境都应该有相同的手动作业来部署5个服务(5个按钮)。environment-1作业和environment-2作业之间的唯一区别是
标记
变量。仅检查提交消息和
环境。名称
。 例如,我应该能够在提交消息中指定
[staging]
,并具有5个单独的按钮,用于将5个服务部署到staging。同样适用于
[生产]

staging-deploy-service1:
  <<: *deploy
  environment:
    name: staging
  variables:
    ServiceName: service2
  tags:
    - dev-staging
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /\[staging\]/

staging-deploy-service2:
  <<: *deploy
  environment:
    name: staging
  variables:
    ServiceName = service2
  tags:
    - dev-staging
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /\[staging\]/

staging-deploy-service3:
  <<: *deploy
  environment:
    name: staging
  variables:
    ServiceName: service3
  tags:
    - dev-staging
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /\[staging\]/

staging-deploy-service4:
  <<: *deploy
  environment:
    name: staging
  variables:
    ServiceName: service4
  tags:
    - dev-staging
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /\[staging\]/

staging-deploy-service5:
  <<: *deploy
  environment:
    name: staging
  variables:
    ServiceName: service5
  tags:
    - dev-staging
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /\[staging\]/
staging-deploy-service1:

我没有完美的解决方案,因为在CI标记中使用变量替换仍然不够,但如果我们忘记了标记,使用可以实现以下技巧:

.service_name:
  parallel:
    matrix:
      - SERVICE_NAME: ['service1', 'service2', 'service3', 'service4', 'service5']
        ENV: ['env1', 'env2', 'env3', 'env4', 'env5']

deploy_service:
  <<: *deploy
  <<: *service_name
  environment:
    name: $ENV
  script:
    - echo $SERVICE_NAME
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ $ENV'
      when: manual
。服务\u名称:
平行:
矩阵:
-服务名称:['service1','service2','service3','service4','service5']
环境:['env1','env2','env3','env4','env5']
部署服务:

我没有完美的解决方案,因为在CI标记中使用变量替换仍然不够,但如果我们忘记了标记,使用可以实现以下技巧:

.service_name:
  parallel:
    matrix:
      - SERVICE_NAME: ['service1', 'service2', 'service3', 'service4', 'service5']
        ENV: ['env1', 'env2', 'env3', 'env4', 'env5']

deploy_service:
  <<: *deploy
  <<: *service_name
  environment:
    name: $ENV
  script:
    - echo $SERVICE_NAME
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ $ENV'
      when: manual
。服务\u名称:
平行:
矩阵:
-服务名称:['service1','service2','service3','service4','service5']
环境:['env1','env2','env3','env4','env5']
部署服务:

我正在尝试调整您的第一个示例,但不是
$CI\u COMMIT\u MESSAGE=~$ENV
,而是需要执行类似于
$CI\u COMMIT\u MESSAGE=~/\[$ENV/]\
的操作,但这不起作用。您可以提出建议吗?另外,有些环境具有不同的提交消息和环境名称,例如
环境:名称:production
$CI\u commit\u message=~/\[prod\]/
。是否可以将这两个值作为单个矩阵元素传递?我正在尝试调整第一个示例,但不是
$CI\u COMMIT\u MESSAGE=~$ENV
,而是需要执行类似于
$CI\u COMMIT\u MESSAGE=~/\[$ENV/]\
的操作,但这不起作用。您可以提出建议吗?另外,有些环境具有不同的提交消息和环境名称,例如
环境:名称:production
$CI\u commit\u message=~/\[prod\]/
。是否可以将这两个值作为单个矩阵元素传递?