How to read local file in runner's host machine when excuting gitlab CI?

196 views Asked by At

I want to excute unit test in gitlab ci stage: test, I only activate one runner machine.

I am sure there is a .jpg file in /path/to/jpg in that runner machine.

And in my unit test, I read this .jpg.

However, when I launch gitlab cicd pipeline, in stage: test, it failed because it cound not read the path /path/to/jpg from host machine's directory.

Is there any method to let ci test can access to the directory path of the runner machine? Thanks

.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

I hope the the unit test in ci task can access to the path /path/to/jpg

1

There are 1 answers

0
stevezkw On BEST ANSWER

I eventually solved this issue by adopting this answer: https://stackoverflow.com/a/39033586/15233792

configure the runner accordingly (config.toml)