执行gitlab CI时如何读取runner主机本地文件?

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

我想在gitlab ci阶段执行单元测试:测试,我只激活一台运行机器。

我确信该跑步机中的

.jpg
中有一个
/path/to/jpg
文件。

在我的单元测试中,我读了这个

.jpg

但是,当我启动 gitlab CICD 管道时,在阶段:测试中,它失败了,因为它无法从主机目录中读取路径

/path/to/jpg

有没有办法让ci test可以访问runner机器的目录路径?谢谢

.gitlab-ci.yaml

image:
  name: gcr.io/kaniko-project/executor:v1.13.0-debug
  entrypoint: [""]

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: $CI_COMMIT_REF_NAME == 'main'

variables:
  DOCKER_TLS_CERTDIR: ""
  DOCKER_DRIVER: overlay2
  IMAGE_NAME: $DOCKER_REGISTRY/$DOCKER_USER/backend

stages:
  - lint
  - build
  - test

lint:
  stage: lint
  image: xxx.com:xxxx/backend-ci-lint:0.0.1
  script:
    - flake8

build:
  stage: build
  script:
    - mkdir -p /kaniko/.docker
    - echo "$DOCKER_AUTH_CONFIG" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile Dockerfile --target runtime --destination ${IMAGE_NAME}:$CI_COMMIT_SHA --destination ${IMAGE_NAME}:latest --insecure --cache=true
    - echo "runtime Docker image pushed to:"
    - echo "$IMAGE_NAME:latest"

test:
  image: $IMAGE_NAME:$CI_COMMIT_SHA
  stage: test
  script:
    - pip install pytest
    - pytest

希望ci任务中的单元测试可以访问该路径

/path/to/jpg

pytest gitlab-ci gitlab-ci-runner kaniko
1个回答
0
投票

我最终通过采用这个答案解决了这个问题: https://stackoverflow.com/a/39033586/15233792

相应地配置运行器(config.toml)

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