Gitlab CI/CD 管道跳过作业

问题描述 投票:0回答:1

因此对于学校来说,我们需要通过 CI/CD gitlab 管道建立一个 terraform 环境。

由于某种原因,我的所有阶段都没有开始。

Gitlab-ci.yml 代码如下:

include:
  - template: Terraform/Base.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/Base.gitlab-ci.yml




stages:
  - Build and Push
  - validate
  - build
  - deploy
  - cleanup


Build and Push:  # Corrected stage name
  stage: Build and Push  # Corrected stage name
  image: docker:25.0.4
  services:
    - docker:25.0.4-dind
  script:
    - apk add python3
    - apk add py3-pip
    - python3 -m venv venv
    - source venv/bin/activate
    - pip3 install awscli
    - aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <accountid>.dkr.ecr.us-east-1.amazonaws.com
    - docker build -t le-repo application/crudapp/.
    - docker tag le-repo:latest <accountid>.dkr.ecr.us-east-1.amazonaws.com/le-repo:latest
    - docker push <accountid>.dkr.ecr.us-east-1.amazonaws.com/le-repo:latest

validate:
  extends: .terraform:validate
  needs: []
  

build:
  extends: .terraform:build
  environment:
    name: $TF_STATE_NAME
    action: prepare
  

deploy:
  extends: .terraform:deploy
  dependencies:
    - build
  environment:
    name: $TF_STATE_NAME
    action: start
  `

正如你所看到的,他没有添加“部署”阶段

enter image description here

感谢您的帮助

尝试在“部署”作业之后添加“销毁”作业,这有效。 还尝试将部署代码更改为以下内容:部署:

extends: .terraform:deploy
  dependencies:
    - build
  environment:
    name: $TF_STATE_NAME
    action: start
  when: always

这也不会启动它。

terraform gitlab-ci
1个回答
0
投票

正如您在提供的源链接中亲眼所见,

.terraform:deploy
作业有阻止其运行的规则。

terraform:deploy:
  stage: deploy
  script:
    - gitlab-terraform apply
  resource_group: ${TF_STATE_NAME}
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $TF_AUTO_DEPLOY == "true"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual

它将仅在默认分支上提交时运行,然后需要手动触发或自动触发,具体取决于是否设置了

TF_AUTO_DEPLOY

© www.soinside.com 2019 - 2024. All rights reserved.