【问题标题】:GitLab manual job on_failure and automatically on_successGitLab 手动作业 on_failure 和自动 on_success
【发布时间】:2023-02-16 02:12:15
【问题描述】:

我找不到适合我的案例的令人满意的解决方案。

我只想在以前的某个工作失败时手动开始工作。有问题的工作进行了验证。我想制作下一份工作手册,以便用户承认某些事情不好,并让他调查问题并仅在他认为可以忽略失败时才继续。

stages:
  - test
  - validate
  - build

lint:
  stage: test
  allow_failure: true
  script:
    - npm run lint

check:reducer:
  stage: test
  allow_failure: true
  script:
    - chmod +x ./check-reducers.py
    - ./check-reducers.py $CI_PROJECT_ID $CI_COMMIT_BRANCH
  except:
    - master
    - development

fail:pause:
  stage: validate
  allow_failure: true
  script:
    - echo The 'validate:reducer' job has failed
    - echo Check the job and decide if this should continue
  when: manual
  needs: ["check:reducer"]

build:
  stage: build
  script:
    - cp --recursive _meta/ $BUILD_PATH
    - npm run build
  artifacts:
    name: "build"
    expire_in: 1 week
    paths:
      - $BUILD_PATH
  needs: ["fail:pause"]

我希望如果 check:reducer 失败,fail:pause 等待用户输入。如果 check:reducer 以 0 退出,fail:pause 应该自动启动或 build 应该启动。

【问题讨论】:

    标签: gitlab conditional-statements gitlab-ci jobs manual


    【解决方案1】:

    不幸的是,这是不可能的,因为 when 关键字是在管道的最开始评估的(即,在任何作业执行运行之前),因此您不能根据以前的作业状态设置 when 条件。

    【讨论】:

      【解决方案2】:

      如果您使用生成的 gitlab-ci.yml 作为子工作流,这是可能的。

      stages:
        - test
        - approve
        - deploy
      
      generate-config:
        stage: test
        script:
          - ./bin/run-tests.sh
          - ./bin/generate-workflows.sh $?
        artifacts:
          paths:
            - deploy-gitlab-ci.yml
      
            
      trigger-workflows:
        stage: deploy 
        trigger:
          include:
            - artifact: deploy-gitlab-ci.yml
              job: generate-config
      

      generate-workflows.sh 脚本根据作为第一个参数传递给脚本的 run-test.sh 的返回码写出一个 deploy-gitlab-ci.yml,它有或没有批准作业。

      您可以使用 include 使自己更轻松,您可以在生成的 deploy-gitlab-ci.yml 文件中包含或不包含批准步骤,并使部署中的步骤可选择需要批准。

      批准-gitlab-ci.yml

      approve:
        stage: approve
        when: manual
        script:
          - echo "Approved!"
      

      部署-gitlab-ci.yml

      deploy:
        stage: deploy
        needs:
          - job: approve
          - optional: true
      

      然后 deploy-gitlab-ci.yml 只是包含要运行的作业:

      includes:
        - approve-gitlab-ci.yml
        - deploy-gitlab-ci.yml
      

      【讨论】:

        猜你喜欢
        • 2016-08-08
        • 2021-01-14
        • 1970-01-01
        • 1970-01-01
        • 2022-10-13
        • 1970-01-01
        • 1970-01-01
        • 2019-10-25
        • 2018-05-19
        相关资源
        最近更新 更多