第二阶段的第一份工作包含GitLab中先前工作的状态

时间:2020-02-14 14:27:33

标签: docker gitlab devops gitlab-ci gitlab-ci-runner

我遇到了一个问题,即在测试阶段的第一份工作在我也没想到的情况下会收到我之前的建造工作的全部状态。为了尽可能重现该问题,我已尽可能简化了该问题。本质上,构建运行并签出我的仓库。 ls -al打印出包含我签出的仓库的工作目录。 test-one运行,跳过git checkout,并打印包含先前构建作业中git checkout的工作目录。运行test-two,跳过git checkout,并打印包含预期空目录的工作目录。

我的问题是,我是否错误地配置了.gitlab-ci.yml文件?我的期望是否缺乏对GitLab应该如何工作的理解?是否是GitLab或运行程序的配置不正确?或者这是一个错误吗?

注意事项:

  • 我正在使用GitLab版本:12.6.4-ee
  • 我不是GitLab管理员
  • 作业互不依赖,脚本仅打印当前工作目录。
  • 我的docker映像只是Linux发行版的干净基础映像,只安装了常见的Linux命令。
  • linux-runner是在我的Linux服务器上作为服务运行的GitLab-runner。
  • 我禁止git在测试作业中检出我的存储库,以查看测试作业中是否存在从构建作业中检出的内容。

下面是简化的.gitlab-ci.yml文件:

image: $DOCKER_REGISTRY/my-image:latest

build:
    stage: build
    tags:
        - linux-runner
    script:
        - ls -al

test-one:
    stage: test
    tags:
        - linux-runner
    variables:
        GIT_STRATEGY: none
    script:
        - ls -al

 test-two:
    stage: test
    tags:
        - linux-runner
    variables:
        GIT_STRATEGY: none
    script:
        - ls -al

2 个答案:

答案 0 :(得分:0)

这似乎是由于我使用GIT_STRATEGY引起的:无。通过删除变量,我再次开始收到预期的行为。

答案 1 :(得分:0)

图片:$ DOCKER_REGISTRY / my-image:latest

stages: # <-- add them all
  - build
  - test1
  - test2

build:
    stage: build
    tags:
        - linux-runner
    script:
        - ls -al

test-one:
    stage: test1 # <-- change this
    tags:
        - linux-runner
    variables:
        GIT_STRATEGY: none
    script:
        - ls -al

 test-two:
    stage: test2 # <-- change this
    tags:
        - linux-runner
    variables:
        GIT_STRATEGY: none
    script:
        - ls -al

根据您的情况,test-onetest-two具有相同的“种类”环境。

通过设置两个不同的阶段,他们将拥有自己的环境